DOS Dir - listing of full path and timestamp

Hi,

(Apologies, I'm sure I'm not the first person to raise this question but so far in my searches haven't found a good answer).

I would like to output a listing per line of filename (including full path) and 'last updated' timestamp. e.g:

Z:\dir1\file1.txt   01/02/2010 10:43
z:\dir1\file2.txt   12/04/2010  09:30
z:\dir1\dir2\file3.txt   26/05/2010  13:01
z:\dir1\dir2\file4.txt   26/05/2010  13:02

I expect 1000+ files to be reported in my real scenario. The ultimate aim is to export to Excel and sort by date.

I had hoped to use the DOS DIR command.

Thanks in advance for any help.

---------- Post updated at 12:37 PM ---------- Previous update was at 06:10 AM ----------

Come on folk - it can't be that hard...

Hi, what have You tried Yourself?

I'm afraid You can't do that with the dir command alone. Do You mean DOS or NT (command.exe or cmd.exe)?
But if You combine it with the "FOR /F" You can extract the needed columns and order them as You want. Have a look at SS64.com Command line reference, an excellent site for explaining some of the most common scripting languages.

I'm not sure about the full path, maybe You would have to combine the command by using dir /s to get the directories, or perhaps tree.
I'm sure it's not THAT hard to find a command to create that list. :wink:

/Lakris

1 Like

Lakris,

Thank you - it is helpful just to have had it confirmed that I haven't missed a DIR switch.
It just feels frustrating that output displayed through the GUI Windows Search program can't be output to file and can't be directly replicated through DIR (I'm using CMD.exe by the way).
I'm sure that lots of people have had the same requirement but my initial Google searches didn't find anything ideal so I was hoping that someone here would have a quick answer. I'll go back to searching or work something out for myself.

GM_AIX

---------- Post updated at 04:44 AM ---------- Previous update was at 04:43 AM ----------

Oh, one extra point...

In my particular case, the directory structure is in a Clearcase stream, so if anyone happened to know a ClearTool solution, that would be a viable alternative on this occasion.

No problems!
I often get frustrated about the shortcomings of "DOS". When I have a complicated script problem it often results in tweaks and workarounds and temporary files, fooling the shell with any number of %%% and """" (where nobody actually knows why it works, it just does, sometimes... also depending if it's in a bat/cmd-file or on an interactive command line) using dozens of programs, that so easily could have been solved with bash alone, possibly with a helper such as sort/grep/find/cut or whatever.

Good Luck!
/L

PS Have a look at the "FOR /R" construct. "For /R - Loop through sub-folders - Windows CMD - SS64.com" Can that help?

DIR /O:A will sort the list by last access time with the earliest time first. I presume you could then sort the files by name if rerquired after exporting them to Excel.

And DIR /? will give you all the options.

You don't mention Windows or Excel versions.

Assuming XP.
This must be done in a Batch File (.bat).
The first script is your exact requirement. The second script puts the timestamp in front of the filename which is more readable.

@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

Just for interest, there are techniques available from Excel if you don't mind a bit of VB programming. For example (but do check your Excel and Windows version and re-search the KB).

XL: How to Put Folder Contents into a Worksheet