Renaming files using a list of names in a txt or csv file

Hello everyone,


I'm trying to use AppleScript (although I'm a total noob to it) to rename the files in a folder (if possible using something like this - set folder to choose folder) to coincide to a list of names (in a txt or csv - can be any extension needed).


To paint the picture clearer I'll have something like this

Files_as_they_areFiles_renamed

01.mkv

Valar Dohaeris.mkv
02.mkvMhysa.mkv
......


Here is what I've tryed so far : (some point through the night I've tryed to repeat part of the process thus the "fcount" but the result was even worse)

set theFolder to choose folder


set ep to {"Valar Dohaeris", "Dark Wings, Dark Words"}

set fcount to 1



tell application "Finder"

set name of file fcount of theFolder to item fcount of ep

end tell

set fcount to fcount + 1



Tnx in advance...

Posted on Jun 28, 2014 11:58 PM

Reply
1 reply

Jun 30, 2014 6:54 AM in response to doala

This will work with a comma separated text file,

i.e.:

Files as the are, Files Renamed

01.mkv, Valar Dohaeris.mkv

02.mkv, Mhysa.mkv


Note that if the file to be renamed exists, it will be overwritten (A test can be added to skip if exists if needed)



set theFoler to POSIX path of (choose folder with prompt "Choose folder with Files" default location path to desktop)

set theFile to POSIX path of (choose file with prompt "Choose TXT file" default location path to desktop)



do shell script "

cd " & quoted form of theFoler & "

while read line

do

OldImageName=${line%,*}

NewImageName=${line#*,}

if [ -e \"$OldImageName\" ] ; then

mv \"$OldImageName\" \"$NewImageName\"

else

echo \"$OldImageName\" >> ~/Desktop/Errors.txt

fi

done < " & quoted form of theFile & "

"

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Renaming files using a list of names in a txt or csv file

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.