findUniqueFileName
April 24, 2008 in Linux, Mac OS X, Vista, Windows XP by chip
FUNCTION findUniqueFileName pPathAndFile
set the itemdel to "."
put item -1 of pPathAndFile into tExtension
delete item -1 of pPathAndFile
put empty into x
REPEAT
IF x is not empty THEN
put pPathAndFile & "-" & x & "." & tExtension into tryThisFileName
ELSE
put pPathAndFile & x & "." & tExtension into tryThisFileName
END IF
IF there is a file tryThisFileName THEN -- find a unique filename
add 1 to x
ELSE
return tryThisFileName
END IF
END REPEAT
END findUniqueFileName