JSI Tip 9240. How can a file name be expaned to include file name, size, date, and time?

If some program or script outputs a file name, and you need file name and file size, and date and time modified, you don't have to rewrite the program or script, or find another one. You can simply use a FOR command and parameter parsing to add information.


If the program or script has already run and created a file that contains fully qualified files names, like c:\folder\Report.txt producted by What files are owned by a security principal, you can open a CMD.EXE window and type:

for /F "Tokens=*" %a in (c:\folder\Report.txt) do @echo %a %~za %~ta

If a line of c:\folder\Report.txt contains "C:\Documents and Settings\Jerry\My Documents\blahblah.doc", it will be displayed as

"C:\Documents and Settings\Jerry\My Documents\blahblah.doc" nnnnn MM/DD/YYYY HH:MM

Where nnnnn is the file size in bytes, and MM/DD/YYYY HH:MM is the date and time the file was last written.

You can pipe the output to another file using:

for /F "Tokens=*" %a in (c:\folder\Report.txt) do @echo %a %~za %~ta>>c:\folder\NewReport.txt

If the program or script simply displays the fully qualified file name, you can run:

for /F "Tokens=*" %a in ('program,exe') do @echo %a %~za %~ta

NOTE: If you use these command in a batch, remember to use %% instead of %.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.