newbie challenge - to sort image sequences by gaps, and move into dirs

Hi there.

This is probably quite simple scripting but a little too much for me! I am after something to do this with applescript.

I have enormous directories of image sequences, scanned from a film scanner. When there is a gap in the frame numbering it means there is a new shot. What I need is a script that scans the list, and then each time it hits a gap in frame numbering it does an action. That action is to move all consecutive files before it into a new directory. Ideally the new directory created would reference the name of the first file in it. So a list like…

0001.tif
0002.tif
0003.tif
0020.tif
0021.tif
0022.tif

would get moved into

0001/0001.tif
0001/0002.tif
0001/0003.tif
0020/0020.tif
0020/0021.tif
0020/0022.tif

Has anyone seen something which will do this, or something I can modify? Help very much appreciated,

Thanks in advance,
Tom.

Model: G5
AppleScript: 2.11
Browser: Firefox 2.0.0.2
Operating System: Mac OS X (10.4)

Hi Tom,

assuming that all name extensions consist the dot and 3 characters (.xxx) and the filename without extension is a number (as string)
try this:

set theFolder to choose folder
tell application "Finder"
	set theList to (get every file of theFolder)
	set theIndex to 0
	repeat with i in theList
		set fName to text 1 thru -5 of (get name of i)
		if (theIndex is not (fName as integer)) then
			try
				set currentFolder to (make new folder at theFolder with properties {name:fName})
			end try
			set theIndex to (fName as integer) + 1
		else
			set theIndex to theIndex + 1
		end if
		move i to currentFolder
	end repeat
end tell

Hi Stefan.

:slight_smile: Thank you very much for your reply, and excellent script! It works a treat. This is going to become a very useful piece of a workflow I am devising.

One thing though - isn’t there always - if the files had some text before the number, like

raw.13245.dpx

could I manually add that, so that the script ignores it? If so where in the script, and would I have to change that for each filename?

Cheers and thanks again,
Tom.

Hi Tom,

in this case the script won’t work and throws an error.
If the raw-files begin always with raw., we can filter this out.
But: the files in one folder must be either with the “raw” prefix or without,
otherwise the order probably get confused. The extension doesn’t matter, if the length doesn’t differ

set theFolder to choose folder
tell application "Finder"
	set theList to (get every file of theFolder)
	set theIndex to 0
	repeat with i in theList
		set fName to text 1 thru -5 of (get name of i)
		if fName begins with "raw." then set fName to text 5 thru -1 of fName
		if (theIndex is not (fName as integer)) then
			try
				set currentFolder to ((theFolder as Unicode text) & fName) as alias
			on error
				set currentFolder to (make new folder at theFolder with properties {name:fName})
			end try
			set theIndex to (fName as integer) + 1
		else
			set theIndex to theIndex + 1
		end if
		move i to currentFolder
	end repeat
end tell