comparing images within subfolders

Hola all.

I use flightcheck here at work to preflight all quark docs that go out of house. I run it twice. Once a week or so before the job is due out, in order to send images to a color correction house. The second is to send to prepress and to give color correction people any new images that have been added to the document.

What I do now is use this script

set oldFolder to choose folder with prompt "Choose CLEAN folder:"
set newFolder to choose folder with prompt "Choose FINAL folder:"
tell application "Finder" to delete (newFolder's files whose name is in (get name of oldFolder's files))

To choose two folders and leave myself with only the new images.

I was wondering if there was a way to ‘drill down’ into each subfolder within the parent folder and compare the ‘images’ folders in each subfolder and leave me with only new images that do NOT exist in the CLEAN folder.

Confused yet?

There are two main folders…CLEAN and FINAL. The structure of each is exactly the same.
CLEAN>Page1>images
and
FINAL>Page1>images

Thanks for any help. I know I probably didn’t explain this very well.

I’m lost but I have a clue and it sounds pretty simple. From the top but different…
SC

add :

tell application “Finder” to delete ((newFolder’s & “images:”) files whose name is in (get name of (oldFolder’s & “images:”) files))

as long as OldFolder’s has the same structure, and your previous line works (I didn’t test it) then this should work.

I continually get an error from the ‘&’ sign in the script.

This should work fine, basically what I said before just forgot to coerce the values so that they combined to the proper folder names.

set oldFolder to choose folder with prompt "Choose CLEAN folder:"
set newFolder to choose folder with prompt "Choose FINAL folder:"
set oldFolder to ((oldFolder & "Page1:images:") as string) as alias
set newFolder to ((newFolder & "Page1:images:") as string) as alias
tell application "Finder" to delete (newFolder's files whose name is in (get name of oldFolder's files))

You might want to add in some error checking to make sure that the folder “Page1:images:” is in the file path.

Yeah, that was a problem I didn’t forsee (same names and stuff).

Here’s a different route I was wondering if it were possible:

All I’m concerned with is the ‘images’ folder. Is there a way to read the contents of each ‘image’ folder into a log (both CLEAN and FINAL), and then have the script compare those logs and THEN delete all but the new images from the FINAL folder?

After messing with the script some more, I was wondering this:

The actual names of folders I’m using are:

T205p01CLEAN_f
and
T205p01FINAL_f

But there are 40 pages. (T205p02CLEAN, T205p03CLEAN, etc.)
And inside each folder there is an ‘images’ folder.

So, every CLEAN folder should have a corresponding FINAL folder. Is there a way to NOT hardwire the exact name of the folder into the script? Then, of course, the ‘205’ will change with every job we do, so that would have to be able to be selected as well. I don’t even really know what options are out there.

Thanks a lot.

I get an error that says “can’t get item 1 of {}”

set parentFolder to alias "Macintosh HD:Users:jmhaynes:Desktop:imagesTest:" --path of your parent folder of folder"p01CLEAN_f"

tell application "Finder"
	set searchFolder to folders of parentFolder whose name contains "p01CLEAN_f"
	if (count searchFolder) > 1 then --two or more folder "p01CLEAN_f"
		set oldFolder to choose folder with prompt "Choose CLEAN folder:"
	else
		set oldFolder to item 1 of searchFolder
	end if
	
	set searchFolder to folders of parentFolder whose name contains "p01FINAL_f"
	if (count searchFolder) > 1 then --two or more folder "p01FINAL_f"
		set newFolder to choose folder with prompt "Choose FINAL folder:"
	else
		set newFolder to item 1 of searchFolder
	end if
	
	set cleanFiles to name of files of (entire contents of oldFolder)
	
	set images_files to files of (entire contents of newFolder) whose name is in cleanFiles and name of parent is "images"
	
	delete images_files --delete the file in folder "images"
end tell

Still get that ‘Can’t get item 1 of {}.’ error.

Could you explain what is happening in the script? It seems to work fine, but I have some questions:

  1. What if, when I collect FINAL docs, all the finals aren’t there? i.e. only half of the jobs have come in at the time I run the script (and then I’ll run it later, when the rest come in)

  2. How are the folders being compared? What is the parameter that the script looks for, in order to know what two folders to compare?

Back again.

Apparently, image name is not enough anymore. I am now going to need to compare modification date also. Where can I add this in? and how?

Thanks a lot, here’s my latest script:


set cleanFolder to choose folder with prompt "Choose CLEAN folder:"
set finalFolder to choose folder with prompt "Choose FINAL folder:"
tell application "Finder"
	set Final_imag_folders to folders of (entire contents of finalFolder) whose name is "images" --LIST OF ALL FOLDERS NAMED "images"  CONTAINED IN "finalFolder"
	set JobFolder to name of (parent of finalFolder)
	set New_image_text to ""
	repeat with thisFinalImageFolder in Final_imag_folders
		set finalPageName to name of parent of thisFinalImageFolder as string -- ex: the result -> "T205p02FINAL"
		set cleanPageName to my replace_chars(finalPageName, "FINAL", "CLEAN") -- ex: change string "205p02FINAL", the  result-> "205p02CLEAN"
		if not (exists folder cleanPageName of cleanFolder) then --09/20/05 Added NOT
			set origPageName to cleanPageName --09/20/05 ADDED
			set cleanPageName to choose folder with prompt "Please select Folder to be used instead of folder " & origPageName default location cleanFolder --09/20/05 ADDED
			
		end if --09/20/05 MOVED UP
		set listOfCleanImages to {""} --  ADDED 9/15
		try --  ADDED 9/15
			set listOfCleanImages to name of (files of (entire contents of folder cleanPageName of cleanFolder) whose name of parent is "images") --ex: listOfCleanImages is name of the images of  folder "images" of folder "...p01CLEAN_f"
		end try --  ADDED 9/15
		set listOfFinalImages to (files of (entire contents of thisFinalImageFolder) whose name is in listOfCleanImages)
		delete listOfFinalImages -- ex :delete images in the folder thisFinalImageFolder if they already exist in CLEAN FOLDER  ,what is left are the new images
		
		set New_image_text to New_image_text & "There are " & (count files of thisFinalImageFolder) & " NEW images in " & name of parent of thisFinalImageFolder & return
		set onecount to 1
		if (count files of thisFinalImageFolder) < 1 then move (parent of thisFinalImageFolder) to trash
	end repeat
end tell
display dialog New_image_text


on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars