1.

Solve : .bat question rename question?

Answer»

I NEED to do a renmame based on the FIRST two line in a .txt file.

Here is how I get the file-

dir /A-D /O:-D /B | findstr txt > list.txt



edlin list.txt

3,9999D

E

This will leve me with two lines in the list.txt "line 1 and line 2"

The NEXT thing I want to do is:

rename (filename in line one of list.txt) newfilename.txt
rename (filename in line two of list.txt) newfilename2.txt

This seems like it should be doable but I cannot FIGURE it out.

Thanks for the help!

Kevin
You could try this

Code: [Select]:: put all the txt files in reverse date order into a file
Dir /A-D /O:-D /B *.txt > list.txt
:: create a dummy blank file
Echo.>blank
:: pull off the top line from the file
Set /P FileName=<list.txt
:: do the rename
Ren "%FileName%" newfilename.txt
:: pull off the next line (its the one after the one we already used, so discard that one)
FindStr /I /V "%FileName%" list.txt > list2.txt
:: pull off the new top name
Set /P FileName=<list2.txt
:: do the rename
Ren "%FileName%" newfilename2.txt
:: tidy up
Del blank
Del list.txt
Del list2.txt

This should do what you want ... but can you guarantee that newfilename.txt and newfilename2.txt will not exist. otherwise it will throw an error

Graham



Discussion

No Comment Found