Date in filename - for cmd file

x509

2[H]4U
Joined
Sep 20, 2009
Messages
2,630
I want to run a cmd file that lists all file in on a drive, something like this:

dir c:\ *.* /s > dirsdate.txt

where the date is replaced by the actual system date. That way, I can do a compare on the txt file from different dates and see all the files on the c: drive have changed. I know that there is some syntax that does this, but I don't know what to look for.
 
What do you mean by "actual system date". Are you referring to dates relating to Created, Modified or Accessed?
 
I think he means that he will change the date in dirsdate to whichever date he likes when he appends the data to the file.

EDIT:

The syntax that the OP is using will show the dates that the files were last accessed. To show the date last modified, use this:

dir c:\ *.* /s /t > dirsdate.txt
 
Last edited:
I think he means that he will change the date in dirsdate to whichever date he likes when he appends the data to the file.

EDIT:

The syntax that the OP is using will show the dates that the files were last accessed. To show the date last modified, use this:

dir c:\ *.* /s /t > dirsdate.txt

I guess I wasn't clear enough. What I want is that if I run this cmd file on January 23, that the filename is something like:

dirs0123.txt

If I run the cmd again on Feb. 5, the filename would be:

dirs0205.txt

To be perfectly honest, I hadn't even thought about the dates returned by dir, that is, date created or date last accessed. What I'm trying to here is back up my entire C: drive, except for those frequent updates from vendors like Symantec for Norton Internet Security, or Microsoft for all those patches, etc., et. Especially for Norton, they update some files almost every day, and if I need to do a restore, I want to restore only permanent files. I figure that NIS is smart enough to know that it has to re-download some files anyway.
 
I guess I wasn't clear enough. What I want is that if I run this cmd file on January 23, that the filename is something like:

dirs0123.txt

If I run the cmd again on Feb. 5, the filename would be:

dirs0205.txt

To be perfectly honest, I hadn't even thought about the dates returned by dir, that is, date created or date last accessed. What I'm trying to here is back up my entire C: drive, except for those frequent updates from vendors like Symantec for Norton Internet Security, or Microsoft for all those patches, etc., et. Especially for Norton, they update some files almost every day, and if I need to do a restore, I want to restore only permanent files. I figure that NIS is smart enough to know that it has to re-download some files anyway.

The only things I can think of are the following:

1) Change the date in the file name the desired date before you run the command.
2) Create a batch file with the following:

echo This Is The Rundate >> D:\files.txt
date /t >> D:\files.txt
dir D:\*.* /s >> D:\files.txt

This will display the date and time right before the command was run and then append everything into the existing file. You could even add this to the scheduled tasks and have it run every day at a specified time.

This wouldn't put the date and time into the filename to which the data is being appended, but it would essentially accomplish the same thing. You would just have to open the file and look at the lines that show the date to see when the command was run. You could then copy and paste the results from two dates into two text files and compare them that way.

There might be another way to do this via VBscript or PowerShell, but I'm not as proficient with those two tools.
 
Last edited:
Code:
dir c:\ *.* /s > %date:~4,2%%date:~7,2%%date:~10,4%-DirList.txt

save as a .bat file
 
Actually it would be easier to do YYYYMMDD format so you can sort by name

In which case it is:

Code:
dir c:\ *.* /s > FileList-%date:~10,4%%date:~4,2%%date:~7,2%.txt
 
Very good. I learned something new here.

Hey, two takeaways here.

1. Props to staticlag. I just ran his script and it worked exactly as I hoped it would.
2. Props to you, Lord Nassirbannipal, for reminding all of us why [H]ardforum is such a great place. We are all constantly learning from each other and helping each other.

x509 ;)
 
Back
Top