I found out I need to use dir /s > filelist.txt to lookup a directory list, what I need is to rename the file to filelist/currentdate.txt, how do I do that?

EDIT: Guess I should have looked a bit more... Including %date% and possibly %time% names the file with the current date

link|improve this question

feedback

2 Answers

up vote 0 down vote accepted

Actually, %DATE% won't work in this case directly -

rename filelist.txt %date%.txt

The above line would give you an error.

The way to go about this is -

set MTH=%DATE:~4,2%
set DAY=%DATE:~7,2%
set YR=%DATE:~10,4%
echo %YR% %MTH% %DAY%

The above lines basically cut up the %DATE% environment variable into little pieces, which can then be used.

So you type in or copy-paste the lines above. Then you just enter -

dir /s > filelist.txt
ren filelist.txt filelist-%YR%-%MTH%-%DAY%.txt

This would give you, for example, filelist-2011-02-04.txt.

Hope this helps!

link|improve this answer
The error is because of the slashes in the date. Note that using %DATE% (even carving it up using substrings) is not portable since the format is localized). – Dennis Williamson Feb 3 '11 at 23:50
feedback

Rename the file to its new name. Make the directory. Move and rename the file to its new location.

rename filelist.txt currentdate.txt
md filelist
move currentdate.txt filelist
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.