I’m struggling with a script to take the filenames of files in a folder, and write them to a text file. The files are named File1, File2, File3, etc, but the resulting list that Applescript produces it this way: File1, File10, File11 … File19, File2, File20, etc.
Is there any way to force Applescript to read the file names and list them numerically? Here’s the basics of the code:
set theItems to every file of theFolder
repeat with i in theItems
set theFilename to name of i
set k to open for access file (i as text) with write permission
set eof of k to 0
write "<img src=\"images/" & theFilename & ".jpg" & "\" alt=\"" & theFilename & "\"" & "/>" & return to k starting at eof
end repeat
This works for me, at least when the numbers are at the end of the filenames. A little bit slow maybe, but fast to implement.
considering numeric strings
set mf to POSIX file (do shell script "ls -1d ~/Library/Caches/TemporaryItems/junk/") as alias as text
set L to {}
tell application "Finder"
set theList to (sort every file of folder mf by name)
repeat with af in theList
set end of L to name of af
end repeat
end tell
end considering
L