renaming files

Hello everybody!
I need help with applescript conserning renaming files, let me explain the situation:
I’ve transfered some audio files from a pc to my mac and all the files extention (“.aiff”) were lost during that transfer. so now i’m trying to program a sentence that can change the name of the files to name+“.aiff” but until now there’s no joy! :?
please gimmy a shout if can help me!
cheers

I am not sure how you want to choose the specific files but–

I have listed below the code to rename such a file after it has been selected in the Finder. You can easily modify it to fit your desires.


property theExtension : ".aiff"

tell application "Finder"
	set theName to the name of the selection
	if theName does not contain theExtension then --prevent duplication of theExtension
		set theName to theName & theExtension
		set the name of the selection to theName
	end if
	activate
end tell

Good Luck !!

Thanks a lot Paul for your promptitude, but as you previewed there is a problem with the selection. it works fine if i select just one file but i’ve got hundreds, do you know what i mean! i thought of selecting all of them but them the variable “theName” can’t be a group. do you have any ideas?
cheers

There are several renaming scripts available at ScriptBuilders. Renamerizer will likely do what you need to do. :slight_smile:

– Rob

try this:

set theFolder to choose folder with prompt "choose a folder of files to rename"
tell application "Finder" to set folderItems to get the name of every file of theFolder --get the name of every file in the folder - skip folders you could add code to limit the listing to only aiff files

repeat with thisName in folderItems --repeat with every file name listed in the chosen folder
	set thisName to thisName as string
	set thisPath to (theFolder as string) & thisName as string --full path to the file so we can work with it
	--check to see if it already has the extension
	if thisName does not end with ".aiff" then --then continue, we'll add it
		--check to see how long the name is now, if it is too long to add ".aiff" we'll have to trim it
		if the (count of characters in thisName) is greater than or equal to 26 then
			--max character count for file names is 31 so if it is already 26 or longer
			--get characters 1 thru 25, then piece the extension to get the new name
			set newName to characters 1 thru 25 of thisName & ".aiff" as string
		else
			--or, if the file name is short enough just piece this name with the extension
			set newName to thisName & ".aiff" as string
		end if
		tell application "Finder" to set the name of file thisPath to newName
	end if
end repeat

If that doesn’t fit the bill check out Macscripter’s Scriptbuilder’s section for file renaming apps.

Best,

Thank a lot guys for your help!! :smiley: i’ve try Mytzlscript script and it worked perfectly, cheers mate!