user1483922
user1483922

Reputation: 131

cmd dir /b/s plus date

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.

Upvotes: 13

Views: 16522

Answers (6)

Dan
Dan

Reputation: 15

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

Upvotes: 0

Charlesdwm
Charlesdwm

Reputation: 71

@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

Upvotes: 0

user12087241
user12087241

Reputation: 121

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;

Upvotes: 3

user4454079
user4454079

Reputation: 1

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 :-)

Upvotes: 0

dbenham
dbenham

Reputation: 130819

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.

Upvotes: 18

Julian Knight
Julian Knight

Reputation: 4923

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

Upvotes: 1

Related Questions