13

I am looking for a cmd shell command in Windows XP, like "dir /b/s" that includes date and time values for each file in result. All data - path, filename and date/time - need to be on one line. Can anyone provide a command to accomplish this? Thank you.

user1483922
  • 131
  • 1
  • 1
  • 3

6 Answers6

18

If you want files only

for /r %F in (*) do @echo %~tF %F

If you want both files and directories then use the DIR command with FOR /F

for /f "eol=: delims=" %F in ('dir /b /s') do @echo %~tF %F

If used in a batch file then %F and %~tF must change to %%F and %%~tF.

dbenham
  • 127,446
  • 28
  • 251
  • 390
  • This meets my needs perfectly. Thank you. – user1483922 Jun 28 '12 at 19:58
  • 3
    @user1483922 - When you get an answer that perfectly meets your needs, you should accept it by clicking on the checkmark near the upper left corner of the answer. Accepting an answer lets others know the question has been answered, it awards you 2 points for taking the time to accept the answer, and it awards the person that posted the answer 15 points. – dbenham Jun 28 '12 at 20:03
3

You can also use use dbenham answer for /f "eol=: delims=" %F in ('dir /b /s') do @echo ... to dump information like:

  • %~zF file length
  • %~dF drive
  • %~pF path
  • %~nF name
  • %~xF extension
  • %~tF date and time

i.e. using the lines below You can make csv dump of directory with subdirectories and file details

for /f "eol=: delims=" %F in ('dir /b /s') do @echo %F;%~zF;%~dF;%~pF;%~nF;%~xF;%~tF;

results:

full_path;size;drive;path;name;extension;date
E:\dump\oc.txt;37686;E:;\dump\;oc;.txt;2020-04-05 20:10;
user12087241
  • 121
  • 1
  • 1
1

There is no direct way of doing this using DIR. You would need to write a wrapper that stripped the extraneous details from a DIR /s

You could use either powershell, vbscript or javascript to do this.

Here is a related answer using PowerShell: How to retrieve a recursive directory and file list from PowerShell excluding some files and folders? though you would need to amend this to add the date/time.

UPDATE: Here is a MAD site that lists a recursive directory walk in loads of different languages: http://rosettacode.org/wiki/Walk_a_directory/Recursively

Community
  • 1
  • 1
Julian Knight
  • 4,716
  • 2
  • 29
  • 42
0

How about something like this:

for /f "tokens=*" %a in ('dir *.* /a:d /b /s') do for /f "skip=5 tokens=1,2,3,4*" %b in ('dir *.* /a:-d') do @if %e neq bytes @echo %a\%e%f %b %c

Simples, although I may have complicated it a little :-)

dibi
  • 3,257
  • 4
  • 24
  • 31
0
@echo off
REM list files with timestamp
REM Filename first then timestamp
for /R %%I in (*.*) do @echo %%~dpnxI %%~tI

@echo off
REM list files with timestamp
REM Timestamp first then name
for /R %%I in (*.*) do @echo %%~tI %%~dpnxI
Charlesdwm
  • 71
  • 5
0

forfiles /M . /S /C "cmd /c echo @path @fdate @ftime" >> dir_path_date.txt

Dan
  • 17
  • 2