TextConverter

Output of File Information via Script

If you want to output properties and other file information of text files within a script or via the command line, you can use programs such as the TextConverter or the TextEncoder for that task. Both programs support both, the output of general information such as the file name, the file folder, the file size or the time as well as the output of textfile-specific properties such as information about the encoding, the line break type or the number of lines, characters or words in the respective file.

In this tutorial, first, we look at how you can use the programs to issue information about individual or multiple files. Then we show you how to pass folders to the programs in order to display information about all files stored in the passed folders and finally we take a look at some overview tables that inform you in list form about all parameters that you can use for the script output:

Even if we use the TextConverter for all sample commands in this tutorial, all commands can also be used with the TextEncoder in the same way.

Output Information about single or multiple Files

In order to show file information with the TextConverter or the TextEncoder, we need 2 important parameters. On the one hand, this is the parameter "-cl", which puts the programs into batch mode and ensures that the programs do not start with a graphical user interface. On the other hand, we need the "info"-parameter. With this parameter we specify which information we would like to display about the text files.

Let us first look at a simple command, which should output the number of words of the file "file.txt" in the command line:

TextConverter -cl C:\file.txt info=%words%

First, we put the program into the batch mode with the parameter "-cl", then we pass the path of the file for which we would like to display the information and finally we pass the text that should be displayed with the "info"-parameter. This text can contain both, arbitrary characters as well as placeholders for the file information (you can find lists with all available placeholders at the bottom of this page). Since we want to show the number of words, we use the placeholder %words% that stands for this information in this example.

Of course, we can also combine several placeholders. In our next example, we would like to output both, the encoding of the file (placeholder %enc% for "encoding") and the line break type of the file (placeholder %lb% for "line break"):

TextConverter -cl C:\file.txt "info=%enc% %lb%"

Because we want to write a space between the encoding and the line break type, we have to put the parameter in quotation marks this time. Otherwise spaces would be interpreted as the beginning of the next parameter and the info-parameter would not remain together.

So far we have only issued information about individual files. But we can also output information from several files at the same time. For this, we specify the paths to all files that we would like to read out:

TextConverter -cl C:\a\file1.txt C:\b\file2.txt "info=The file %filename% has %chars% characters, %lines% lines, %words% words, a size of %size-kb% KB and is stored in the folder %folder-1%."

In this case, the TextConverter or the TextEncoder will output a line for each file in the console. So that we are able to assign each of the lines to the right file, we can use the placeholders of the categories file name and file folder. In this example, for example, with %filename% we output the name of the file with file extension (here "file1.txt" and "file2.txt") and with %folder-1% we output the direct folder in which the respective file is saved (here "a" and "b"). With the placeholder %size-kb%, the size of the file is output in kilobytes. If we write %size% (as in the next example) instead, a unit is used that fits to the size of the file. Further placeholders for the file size can be found in the section about placeholders for the size of the file.

Output Information about Files from Folders

In order to list the information from all files from a folder, we can also pass the path from one or more folders to the TextConverter or the TextEncoder. This can be useful, for example, if we want to display information of very much files or if we do not know exactly what the files are called in a certain folder.

The syntax is the same as with files. We simply pass the folder paths instead of the file paths:

TextConverter -cl C:\folder "info=%filepath% %encbom% [%size%]"

With this command, we create a file list of all files from the folder "C:\folder" with the full file path, the file size and with information about the encoding in which the files are stored and whether the files have a byte order mark or not. Here again, the placeholders for the file name and the file folder are particularly useful in order to be able to assign the information from the output to the files.

Placeholders

In the examples, you have already met some of the placeholders that you can use in addition to arbitrary characters and letters with the parameter "info". You can find an explanation of these placeholders as well as of all other available placeholders in the following lists. The lists are sorted by placeholders for the file name, the file folder, the file size, placeholders for text-file-specific properties and placeholders for the time. All placeholders can be combined with each other, also used several times within a call and supplemented by any other characters.

Please note that in some situations, for example in Windows Batch Scripts, you have to double the percentages (for example %%words%% instead of only %words%). Otherwise, the placeholder can be interpreted as an variable by Windows and is therefore empty in most cases.

Placeholders for the File Name

To output the file name or the path of a file, you can use the following placeholders:

%filepath%Path of the file with file name - for example "C:\folder\file.txt"
%path%Path of the file without file name - for example "C:\folder\"
%filename%Name of the file with file extension - for example "file.txt"
%name%Name of the file without file extension - for example "file"
%name,x,y%Name of the file from character x to character y. For example, %name,1,3% corresponds to the first three characters of the file name, %name,2,5% corresponds to the second through fifth character.
%ext%Extension of the file - for example "txt"
%ext,x,y%Extension of the file from character x to character y

Placeholders for the File Folder

To output particular folders of the path of a file or to output its drive, you can use the following placeholders:

%folderX%
%folder‑X%
The placeholders %folder1%, %folder2%, %folder3% up to %folder50% as well as %folder-1%, %folder-2%, %folder-3% up to %folder-50% are standing for the names of the folders in which the file is stored. Positive numbers like in %folder1% count the folders from the drive to the file, negative numbers like in %folder-1% count the other way around. Accordingly, the placeholder %folder1% is standing for the first folder of the path, %folder-1% is standing for the first folder below the file. When having the file C:\Holidays\Trips\Norway\File.txt %folder1% will be replaced with "Holidays", %folder-1% with "Norway", when renaming the file. Correspondingly, the placeholder %folder2% is standing for the second folder in the path, this is "Trips" in that case (%folder-2% would be the same, counted from the top).
%drive%Drive of the file - for example "C:"

Placeholders for the File Size

The following placeholders can be used to output the size of the file:

%size%File size in a unit suitable for the file size
%size-b%File size in bytes
%size-kb%File size in kilo bytes without decimal places
%size-kb-X%File size in kilo bytes with X decimal places
%size-mb%File size in mega bytes without decimal places
%size-mb-X%File size in mega bytes with X decimal places
%size-gb%File size in giga bytes without decimal places
%size-gb-X%File size in giga bytes with X decimal places
%size-tb%File size in tera bytes without decimal places
%size-tb-X%File size in tera bytes with X decimal places

Placeholders for textfile-specific Properties

Textfile-specific information can be output in the command line or within a script with the following placeholders:

%enc%Encoding of the file (for example "utf8" or "utf16le")
%bom%Presence of a Byte Order Mark (for example "0" or "1")
%encbomEncoding and Byte Order Mark (for example "utf8" or "utf8 bom")
%lbLine break type of the file (for example "crlf" or "lf")
%linesNumber of lines of the file
%charsNumber of caracters of the file
%wordsNumber of words of the file

Placeholders for the Time

If you want to output the current time or the current date, you can work with the assortment of the following placeholders:

%date%Current date in the format "year-month-day" (two or four digits with leading zeros if necessary; short form for %yyyy%-%mm%-%dd%)
%dd.mm.yyyy%Current date in the format "day.month.year" (two or four digits with leading zeros if necessary; short form for %dd%.%mm%.%yyyy%)
%yyyy-mm-dd%Current date in the format "year-month-day" (two or four digits with leading zeros if necessary; short form for %yyyy%-%mm%-%dd%)
%time%Current time in the format "hour-minute-second" (two digits with leading zeros if necessary; short form for %hh%-%ii%-%ss%)
%hh-mm-ss%Current time in the format "hour-minute-second" (two digits with leading zeros if necessary; short form for %hh%-%ii%-%ss%)
%hh-mm%Current time in the format "hour-minute" (two digits with leading zeros if necessary; short form for %hh%-%ii%)
%yyyy%Current Year written with four digits
%yy%Current Year written with two digits
%mm%Current Month, always two digits, leading zeros if necessary
%m%Current Month, one or two digits without leading zeros
%dd%Current Day, always two digits, leading zeros if necessary
%d%Current Day, one or two digits without leading zeros
%hh%Current Hour, always two digits, leading zeros if necessary
%h%Current Hour, one or two digits without leading zeros
%ii%Current Minute, always two digits, leading zeros if necessary
%i%Current Minute, one or two digits without leading zeros
%ss%Current Second, always two digits, leading zeros if necessary
%s%Current Second, one or two digits without leading zeros