Strange error with custom renamer script

Hi all.

I put together a file renaming script with the invaluable help of some fellow forum posters. It seemed to work perfectly, renaming files in a multi-level directory according to a delimited tabbed .txt file from excel.

The problem is that I started futzing with it and to allow the user to choose the directory and .txt filed that would rename the files in the directory, I started getting this error:

To my eye, everything in my script looks the same as before. I posted it below - it’s short and sweet. I can’t seem to figure out why it’s now getting an error. I’d still love to enable it to prompt the user for the directory and file, but I have to fix this and I’m quite stumped.

Any input would be greatly appreciate. Thank you so much. If you address the “prompt user for” question, I would be doubly in your debt. That’s another can of worms I suppose.

property sourceFolder : "MacHD:path:to:folder" -- adjust as appropriate

property textFile : "MacHD:path:to:file"

-- 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
	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

-- we're going to use the Finder to do this
tell application "Finder"
	-- loop through the list
	repeat with aFile in filenameList
		-- work out the current file name
		set codified_name to (sourceFolder & ":" & (text item 1 of aFile)) as string
		-- get the real name of the file
		set real_name to text item 2 of aFile
		-- and rename it
		set name of file codified_name to real_name
	end repeat
end tell

Model: PowerbookG5
AppleScript: 1.10.7
Browser: Firefox 2.0.0.7
Operating System: Mac OS X (10.4)

You messed up my script !!! :wink:

replace


property sourceFolder : "MacHD:path:to:folder" -- adjust as appropriate
property textFile : "MacHD:path:to:file"

with


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

and delete everything after the display dialog line

You’re amazing. That fixed everything. I think I’d forgotten to save changes when I consolidated the script – or something stupid.

Anyhow, thank you very, very much. For the record, this script works for a 1:1 rename of files using a delimited tabbed .txt file over multiple levels and prompts the user for the directory and .txt filed that details the old and new names.