Jump to content

Workflow to Check Folder for Missing Files


Recommended Posts

Hello Brainy Alfred Workflow Geniuses,

 
This has to do with scripting more than workflows really, but I don't know where else to go for help. I am new to scripting and don’t even know where to start on this, so I am wondering if there is a way to do what I want.
 
I want to be able to run a script on a folder or group of folders to find out if there are any missing items in the folder, that is, if the series of items is missing any numbers. There might be more than one way to do this, and I’m open to any way that works.
 
The script should display a dialog when the folder doesn’t have the right number of files in it.
 
In order to know what the number of files should be (and this is what I want to automate) I have to look at the serial numbers on the files within the folder. The number of files in the folder should equal (the highest serial # - the lowest serial #) plus 1.
 
Here is a real-life example. The folder to be looked at it contains a folder inside it and inside that is a set of serially numbered .dpx files numbered from 1000 to 1150.
 
tb0020_comp_v028 /
2370x1800 /
tb0020_comp_v028.1000.dpx - tb0020_comp_v028.1150.dpx
 
The script should look at the highest/last serial number (1150), subtract the lowest serial number (1000), add 1, and compare that to the number of .dpx files in the folder. There should be 151 files in the folder.
 
Or, like I said, maybe there is a script that can spot whenever a series of files misses a number. 
 
Ideally if the folder were missing one of the files in the series, the alert would say something like
 
“Broken Frames Detected! Missing tb0020_comp_v028.1032.dpx and tb0020_comp_v028.1047.dpx”
 
Can anyone point me in the right direction as far as creating something like this?
 
Thank you very much,
Liat
Link to comment

Here's a version in Applescript which you can run in Script Editor to get you started.  This assumes that there are four-digit codes as the last four characters of the file prior to the extension, and that the filenames are identical other than the codes.


tell application "Finder"
	set theFiles to items of window 1
	set theList to {}
	set missingFiles to {}
	
	sort theFiles by name
	
	-- build a list of the digits in the filenames
	repeat with f in theFiles
		set theName to name of f as string
		set strLength to (get count of characters in theName)
		-- get the four characters prior to file extensions
		set theNo to ((get characters (strLength - 7) thru (strLength - 4) of theName) as string) as integer
		set theList to theList & theNo
	end repeat
	
	-- check for missing numbers in the list of digits
	set lastItem to 0
	repeat with n in theList
		if (n as integer) is not equal to (lastItem + 1) then
			set missingFiles to missingFiles & ("File " & lastItem + 1 & " is missing")
		end if
		set lastItem to n
	end repeat
end tell

return missingFiles
Edited by dfay
Link to comment

 

Hi dfay,

 
I just wanted to say thank you so much for posting this solution for me to try!
I got super busy at work yesterday and today so I haven't been able to test it out but I will do so very soon.
 
Thank you again!
 
Liat

 

 

 

Hi there,

 

Thank you so much for this script! I tried it out today but the script editor returned this result, whether or not any files were actually missing:

 

{"File 1 is missing"}

 

In order to run the script, I selected the folder in Finder and then ran the script. Is there something I'm doing wrong?

Thank you,

Liat

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...