Hi there, I have the following script
set excelFile to choose file with prompt "Choose the Excel file" of type {"XLS6", "XLS7", "XLS8"}
set theFolder to choose folder with prompt "Choose the folder containing the files to rename"
tell application "Microsoft Excel"
open excelFile as text
tell active sheet to set P to value of used range
end tell
set {fileNames, EAN} to {{}, {}}
repeat with i in P
set end of fileNames to item 1 of i
set end of EAN to item 2 of i
end repeat
set theFiles to list folder theFolder without invisibles
repeat with oneFile in theFiles
set idx to BinarySearch(fileNames, contents of oneFile)
set x to item idx of EAN
tell application "Finder" to set name of file oneFile of folder theFolder to item idx of EAN
end repeat
on BinarySearch(theList, theValue)
script o
property l : theList
end script
set low to 1
set high to (count theList)
repeat until (low = high)
set mid to (low + high) div 2
if ({theValue} is in items low thru mid of o's l) then
set high to mid
else
set low to mid + 1
end if
end repeat
if (item low of o's l is theValue) then return low
return false
end BinarySearch
Which works perfectly on small numbers. However we are going to renaming some 8000+ files and there are bound to be one of two files that don’t exist. So, if the file does not exist can it write that filename to a text file and carry on?