File extensions...

Im working on a script that adds a file extension to selected specific item types. But if the item already has an extension, it still adds it. Is there a way to skip files that already have the extension?

Thanks

Once you have a reference to a file, you can use info for to get the extension:

set aa to choose file
(info for (aa as alias))'s name extension

According to the Standard Additions dictionary, however, this command is being deprecated, and we are advised to use this instead:

set aa to choose file
tell application "System Events" to get aa's name extension

Good luck,

Thank you.

ok, I have infoFor finding the file to which I want to add the .ext, but I need to tell it to skip any files that already have that .ext. Otherwise it will keep piling it on even if it encounters a file with that .ext: “Filename.ext.ext.ext.ext” - after running the script 4 times.

~N

Your best bet is to test each file first to see if it already possesses the proper extension. If so, skip that file. Something like this pseudocode:

repeat with a_file in List_of_files
	if (info for (a_file as alias))'s name extension ≠ "whatever" then
		--add the proper file extension here
	end if
end repeat


I use this snippet to get the name separate from the extension:

tell (info for file_path without size) to set {file_name, file_extension} to {name, name extension}

I ran into a problem with a script that did alot of file renaming and dealing with the Finder not keeping-up, so I got this from Mike Alldrit at LateNightSoftware (I do my fancier apps in FaceSpan) for renaming files:

set contianerAlias to container of path_to_fix as text
do shell script "mv " & ¬
	quoted form of (POSIX path of path_to_fix) & ¬
	" " & quoted form of ((POSIX path of contianerAlias) & new_name)

Not sure if this helps or not.