/ Published in: DOS Batch

This example shows how you can split the output lines of e.g. a dir command. It also shows how to use a pipe to reduce the resulting lines by the findstr command.
Explanation:
This command calls "dir *.dll" and filters the results by findstr command through a pipe "|". The result of this is a list of all dll-files which contains the string "text" in it's name.
Now the for-loop takes each of these lines and splits them by the signs given in the "delims=.: " part. The "tokens=1,2,3" will send the first three parts of the split string to the explicit defined variable %i and the implicit defined variables %j and %k.
You can start counting your variables from every sign between a-z or A-Z. You will get more information about this on your command line with "for /?".
If you want to use this in a batch file, replace all % with %%.
This example will give you the date of alle found files in the format DD MM JJJJ (on a german windows box). If you use mor than three tokens or other characters as delims, you can get different results. Just play around.
Explanation:
This command calls "dir *.dll" and filters the results by findstr command through a pipe "|". The result of this is a list of all dll-files which contains the string "text" in it's name.
Now the for-loop takes each of these lines and splits them by the signs given in the "delims=.: " part. The "tokens=1,2,3" will send the first three parts of the split string to the explicit defined variable %i and the implicit defined variables %j and %k.
You can start counting your variables from every sign between a-z or A-Z. You will get more information about this on your command line with "for /?".
If you want to use this in a batch file, replace all % with %%.
This example will give you the date of alle found files in the format DD MM JJJJ (on a german windows box). If you use mor than three tokens or other characters as delims, you can get different results. Just play around.
Expand |
Embed | Plain Text
Comments
