What's the chances of a file name ending in a unusual char?

G’day

I’ve got a bit of a dilemma.

I’ve written a batch file/folder renamer,

http://scriptbuilders.net/files/itemrenamer2.4.html

but one of the users reports that the number usuallly appended to the name before the extension is actually being placed after the extension on odd occasions.

I haven’t been able to duplicate the error.

Is it possible that something like a carriage return is located after the extension name, and the script calling the Finder can’t ‘see’ it?

Thanks,

Santa

The bit of script checking the extension is…


on GoAndRename(TheFolderItem)
	try
		tell application "Finder"
			set temp3 to ""
			set AddToName to 2 -- The 'add-on to name' item
			set NameItem to TheFolderItem as alias
			set TheName to (displayed name of (info for (NameItem)))
			set NewName to TheName
			if TheName is not in AllTheExistingNames then
				set AllTheExistingNames to AllTheExistingNames & TheName
				return TheName
			else
				if (extension hidden of (info for (NameItem))) = false then
					set temp3 to "." & (name extension of (info for (NameItem)))
					-- Now set main string for name, minus extension
					if temp3 = ".missing value" then
						set temp3 to ""
					else
						set TheName to my replace_chars(TheName, temp3, "")
					end if
				end if
				
				repeat
					set NewName to TheName & " " & (AddToName as string) & temp3
					(* Now we have to check two states...
						1. Does the re-named file exist in the destination folder,
						2. is there a conflict in the present folder if we re-name.
						*)
					if NewName is not in AllTheExistingNames then
						if my CheckAllTheNewItems(NewName) < 2 then
							exit repeat
						end if
					else
						set AddToName to AddToName + 1
					end if
				end repeat
			end if
		end tell
	end try
	set AllTheExistingNames to AllTheExistingNames & NewName
	return NewName
end GoAndRename

Model: G5 1.8 GHz
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi, Santa.

The file won’t unstuff on either of my machines (“StuffIt Expander” reports a “Format error”, #17540), so I can’t see what’s happening in the rest of the script. But I see from what you’ve posted that you’re using ‘displayed name’ and are relying on ‘extension hidden’ for some decision. When messing around with the names of files, you should use their proper ‘name’. What’s displayed or hidden is a matter of user preference, but a file’s ‘name’ is its actual name on the disk.

Hello

As I don’t know the contents of called handler I’m not sure of what I modified but as is it may be helpfull


on GoAndRename(TheFolderItem)
	try
		tell application "Finder"
			set temp3 to ""
			set AddToName to 2 -- The 'add-on to name' item
			set NameItem to TheFolderItem as alias
			set TheName to name of NameItem
			if TheName is not in AllTheExistingNames then
				set AllTheExistingNames to AllTheExistingNames & TheName
				return TheName
			else
				set nameExt to name extension of NameItem
				if nameExt is not "" then
					set temp3 to "." & nameExt
					set TheName to text 1 thru -(temp3's length) of TheName
				else
					set temp3 to ""
				end if
				
				repeat
					set NewName to TheName & " " & (AddToName as string) & temp3
					(* Now we have to check two states...
						1. Does the re-named file exist in the destination folder,
						2. is there a conflict in the present folder if we re-name.
						*)
					if NewName is not in AllTheExistingNames then
						if my CheckAllTheNewItems(NewName) < 2 then
							exit repeat
						end if
					else
						set AddToName to AddToName + 1
					end if
				end repeat
			end if
		end tell
	end try
	set AllTheExistingNames to AllTheExistingNames & NewName
	return NewName
end GoAndRename

Yvan KOENIG (from FRANCE dimanche 1 avril 2007 13:52:52)

G’day

Thanks Yvan, that works a treat; however I had to alter one line to remove the extension correctly



   if nameExt is not "" then
                   set temp3 to "." & nameExt
                   set TheName to text 1 thru -((temp3's length) + 1) of TheName
               else
                   set temp3 to ""
               end if