-------------------------------------------------------------------------------------------
set destinationDir to "Mercury:Users:chris:test_directory:Destination_Directory:"
set newFilePath to missing value
set prefixText to destinationDir & "File_Name "
set suffixText to ".txt"
set pathList to addPaddedEnumerationToString(prefixText, suffixText, 2, 25)
repeat with theItem in pathList
if exTant(theItem) = false then
set newFilePath to contents of theItem
exit repeat
end if
end repeat
if newFilePath ≠ missing value then
# Process an item using the name or path from newFilePath
newFilePath
end if
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on addPaddedEnumerationToString(prefixText, suffixText, numWidth, listLength)
if prefixText ≠ "" then set prefixText to prefixText
if numWidth > 5 then error "The value for numWidth is too big!"
set paddedNumList to {}
repeat with i from 1 to listLength
set end of paddedNumList to prefixText & (text -numWidth thru -1 of ((100000 + i) as text)) & suffixText
end repeat
return paddedNumList
end addPaddedEnumerationToString
-------------------------------------------------------------------------------------------
on exTant(_path) # Takes an HFS, Posix, or ~/Posix path as input.
try
if _path is "~" or _path is "~/" then
set _path to (POSIX path of (path to home folder as text))
else if _path starts with "~/" then
set _path to (POSIX path of (path to home folder as text)) & text 3 thru -1 of _path
end if
if _path starts with "/" then
alias POSIX file _path
else
alias _path
end if
return true
on error
return false
end try
end exTant
-------------------------------------------------------------------------------------------