Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
add comment

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!

share|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
add comment

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.