Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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

You must log in to answer this question.