Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmd dir /b/s plus date

Tags:

date

path

cmd

dir

bare

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.

like image 690
user1483922 Avatar asked Jun 26 '12 20:06

user1483922


People also ask

What does dir B mean?

The command DIR /b will return just a list of filenames, when displaying subfolders with DIR /b /s the command will return a full pathname. To list the full path without including subfolders, use the WHERE command.

What does dir s do in cmd?

The dir command displays a list of files and subdirectories in a directory. With the /S option, it recurses subdirectories and lists their contents as well.


3 Answers

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.

like image 195
dbenham Avatar answered Oct 17 '22 15:10

dbenham


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;
like image 26
user12087241 Avatar answered Oct 17 '22 15:10

user12087241


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

like image 1
Julian Knight Avatar answered Oct 17 '22 16:10

Julian Knight