Split output of dir command into parts

/ Published in: DOS Batch
Save to your folder(s)

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.
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.

Copy this code and paste it in your HTML
  1. for /f "tokens=1,2,3 delims=.: " %i in ('dir *.dll^|findstr /i "text"') do @echo %i %j %k

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.