Changing filenames - if name exists in a variable list


I’m struggling to achieve the following. Any help or pointers would be appreciated.

I have a folder full of images.

I have a document (TextEdit / Quark - doesn’t matter) which contains a list of most, but not all, of the filenames in the folder and the new filename (tabbed to the right of the old name) they should be getting.

oldfilename (tab) newfilename
oldfilename (tab) newfilename
oldfilename (tab) newfilename

I need to go through every image in the folder,

	set theImagesFolder to (choose folder with prompt "Select folder containing images.")
	set Imagelist to every item of the theImagesFolder

check to see if each filename exists in my list and, if it does, change it to the specified new name.

repeat with u from 1 to the count of Imagelist
		tell item u of Imagelist
		[currently garbage!]
		end tell
end repeat

The new filenames are unique but cannot be inferred from the old filename (i.e. it’s not a truncation or a find / change).

Thanks in advance for any assistance.


AppleScript: 2.1.2
Browser: Firefox 3.5.3
Operating System: Mac OS X (10.4)


I haven’t tested it, but try this

set theImagesFolder to (choose folder with prompt "Select folder containing images.")
tell application "Finder" to set {nameList, fileList} to {its name, it} of files of the theImagesFolder

set fileNameList to paragraphs of (read file "MacHD:path:to:file.txt")
set {TID, text item delimiters} to {text item delimiters, tab}
repeat with oneLine in fileNameList
	set {oldName, newName} to text items of oneLine -- assumes oldName tab newName
	if oldName is in nameList then
		repeat with i from 1 to count nameList
			if item i of nameList is oldName then
				tell application "Finder" to set name of item i of fileList to newName
				exit repeat
			end if
		end repeat
	end if
end repeat
set text item delimiters to TID

Thank you.

I’ll get stuck into this.

Works a treat - thanks again