Rename script doesn't work on external drive

I thought I’d perfected my renaming script with the expert help of posters here, adding a logging routine to catch failures. Everything checks out on my local drive, but as soon as I run it on an external FireWire drive it throws the following error:

Basically, it’s getting hung up on this line:

tell application "Finder" to set name of (POSIX file foundFile as alias) to real_name

But it never had that issue on the local drive. I’ve seen posted here and elsewhere about Ignoring Permissions. Could that be the issue? I’m wracking my brains as to why this script suddenly has issues.

I should also mention that the volume of files being renamed has gone up considerably, but I’m not sure why that would cause this POSIX problem. Very frustrating, as I felt I had polished this thing off and at least moved to the next level in my meager understanding of AS.

The script, the product of guidance and past work by StefanK and CalvinFold, is below:

--
-- DECLARE PROPERTIES
--
-- debugging on?
property g_debug : true

--basic file path and names
property g_home_folder_path : "LUX_Archive2"
property g_log_file_name : "Rename_Log.txt"


set sourceFolder to (choose folder) as text
set textFile to (choose file of type "TEXT") as text

-- read in the list of names
set filenameList to paragraphs of (read file textFile)

-- in order to break out the two fields we need to play
-- with text item delimiters
set {oldDelims, text item delimiters} to {text item delimiters, tab}

set err to 0
set allFiles to count filenameList
repeat with aFile in filenameList
	
	set {codified_name, real_name} to text items of aFile
	set foundFile to do shell script "/usr/bin/find " & quoted form of POSIX path of sourceFolder & " -name " & quoted form of codified_name
	if foundFile is "" then
		set err to err + 1
		my logMe("FILE NAME: " & codified_name as text, 0)
	else
		tell application "Finder" to set name of (POSIX file foundFile as alias) to real_name
	end if
end repeat

set text item delimiters to oldDelims
set msg to (allFiles as text) & " files processed"
if err > 0 then set msg to return & (msg & err as text) & " files not found"
display dialog msg



-- Log Entry Generation
-- With help from StephanK and CalvinFold of MacScripter
-- http://bbs.applescript.net/viewtopic.php?pid=76607#p76607

on logMe(log_string, indent_level)
	if g_debug is true then --allows turning the debugger on and off so my logMe's can be left in final version
		set log_target to ("LUX_Archive2:Rename_Log.txt") as text
		try
			set log_file_ref to open for access file log_target with write permission
			repeat indent_level times
				write tab to log_file_ref starting at eof
			end repeat
			write ((log_string as text) & return) to log_file_ref starting at eof
			close access log_file_ref
			return true
		on error
			try
				close access file log_target
			end try
			return false
		end try
	end if
end logMe




The text of the POSIX path is doubled in that error message, but I did not see anything in the code code that would do it (if you take as an assumption that find will only print a single filename for your codified_name”something that is not true in the general case). It might be interesting to see what the “control file” (from another thread, your tab-delimited Excel file, right?) entry looks like for this file. You might try changing the code to this to do some more diagnostic logging for the error:

try
	tell application "Finder" to set name of (POSIX file foundFile as alias) to real_name
on error m number n
	my logMe("RENAME FAILED: " & foundFile & " (" & codified_name & ") to " & real_name & "; error " & n & ": " & m, 0)
	--error m number n -- reissue the error; uncomment this line to make the script abort on an error here
end try

That’s a great suggestion. Adding that log entry allowed me to find out that the script can’t handle duplicate strings of characters in the files it’s renaming - even if those files do not have the same exact name. It’s one of those things I just took for granted and didn’t investigate in my directory since it’s so large. It goes to show that you have to know your material first.

Thank you so much - your input led to the breakthrough. I’m hoping my final order of business will be contraining the script so it only finds file names that EXACTLY match the entry in the Excel file that guides the rename.