Vipercat on 23/4/2010 at 04:37
I am trying to find out how to rename files on my pc using the names strored in a text document
eg. the file on the pc is called C07_08.dat the text file has the following line "3am Eternal KLF 03:15 121 BMG C07.08
I have over 1000 of these files so I dont really want to rename them all one at a time
What I would like is a batch file or something that will see the C07.08 and find the corresponding file C07_08.dat and rename it 3am Eternal.dat or if possible .mpeg. I could probably import the text file into excel if that makes it easier
can anyone help ?
ZylonBane on 23/4/2010 at 05:27
It would help if you could describe the problem in a comprehensible way.
addink on 23/4/2010 at 07:32
Off the top of my head, if you're into excel:
Import the file into excel*.
Setup the columns so they read like the dos command to rename files:
[indent]ren "old name.xyz" "new name.abc"[/indent]
Add columns filled with text like '
ren "' and '
.mpeg"'. Delete superfluous columns. **
Save as plain text (tab delimited).
Open the text in a plain text editor that has a replace function. Replace tabs with nothing. Save the text, (re)name it so it'll have the '.bat' file name extension. And run that.
(It's always wise to make backups of the original files before running any kind of batch processing on them.)
* If importing proves a problem, use the text editor to replace spaces with tabs prior to importing. If a variable number of spaces are used to delimit the values, first reduce them to single spaces by running replace " " (double space) with " " (single space) a number of times until only single spaces are left.
** Make sure spaces of the dos command are in place, if that proves to be a problem in the next phase use a placeholder character string and switch it for a space in the plain text editor.
EDIT:
If you are in need of a free text editor that has a powerful enough replace function: (
http://www.scintilla.org/SciTEDownload.html)
Vipercat on 25/4/2010 at 14:15
um .. what
Im afraid im no genius when it comes to programming or excel
I just know how to do basic things
I have managed to setup an excel file that has four columns
Column a has the file name i need and column D has the file reference
but that is as far as i have got
apparently python would have no problem with this but the only expereience i have had with python is my pet
Vipercat on 27/4/2010 at 13:48
Ok I found out how to do it so im going to post the basic outline along with the script so that if anyone needs to do something similar or need to remember it will be here
Firstly I used a program called SciTED as suggested by addink to remove the unwanted spaces and replace them with commas, then I loaded the text file into Excel using the commas as delimiters to create 4 columns A - D, I then saved the result as a text file again using the columns as tab delimiters.
Next in Windows 7 I opened Powershell using the search in the start menu and navigated to the drive and folder that had the files to be renamed in and the text file. I then typed the following code into Powershell and hit enter and in less than 5 seconds over 1800 files had been renamed just as I wanted :)
Code:
GC TestFile.Txt | % { if (test-path "$($_.Split("`t")[3]).dat") { rename-Item "$($_.Split("`t")[3]).dat" "$($_.Split("`t")[0]).mpeg" } }
Of course there may be a simpler way to do this and I may not have used the exact correct terms but you get the idea ... i hope