Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename files based on a text file

Status
Not open for further replies.

sylro

Technical User
May 19, 2007
31
RO
Hi all

Look, the situation is the follow: I have a folder, c:\folder1, containing 'n' .wav files and a text file, Log.txt.
Log.txt contains all the .wav files names plus other things (start_time, stop_time, duration).
The problem is to rename the .wav files with the corresponding lines from Log.txt (all the lines in the Log.txt correspond with the .wav files, one by one).

Initially I was thinking that a script to do this is not big deal but I realize that is only for professionals.
What are you saying? Could be a script to do all these?

Thanks in advance
sylro
 
how is each line of the text file delimited (ie "name, start_time, end_time..etc")? are the files named like "1.wav" "2.wav" and the first line of the text file correspond to 1.wav and the second correspond to 2.wav? It would be a fairly straight forward script to do that.
 
Well, assuming you're using 24 hour time, it would be pretty easy. Problem is a ":" cannot be part of a file name. This line of code takes the contents of the file info.txt and renames the files based on teh contents of the file.

So, my directory contents is info.txt, 1.txt, 2.txt, 3.txt. The line of code that would make the change is:

Code:
for /F "tokens=1,2,3,4 delims=," %1 in (info.txt) do ren %1 "%2%3%4.txt"

The contents of info.txt is:

1.txt, 1100, 1101, 1 Min
2.txt, 1102, 1104, 2 Min
3.txt, 1105, 1108, 3 Min

The resulting files are:

1100 1101 1 Min.txt
1102 1104 2 Min.txt
1105 1108 3 Min.txt

There may be a way round the ":" problem, but I'm not sure off the top of my head. If you don't have : in your times, it will make life easier, but this should be doable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top