Copying selected images from a large collection to a new collection

Hi!

:?:
I have a problem which an applescript would solve, and, as I think, the

easiest thing in the world but I don’t know how to make the script. :?

Please help if you faced the same problem and you know how to get

through!

We are working on a brochure with more than 200 pictures in each issue.

We use a picture database with more than 10 000 pictures. This database

is a simple collection of EPS files ordered in systematic folders.

During the work, some of this pictures are copied to an other place, and

some changes are made in these files. These changes are image corrections

which we have to keep.

So, in the end, we have hundreds of files of the original collection

copied to an other place and modified but with the same filename. :x :x :x

:arrow:
The task is to copy all of these modified files back to the original

folder overwriting the old file.

So, the applescript should do the following:

  1. take the first filename

  2. find the file with the same name in the original root directory

  3. if found, owerwrite it with new one

  4. go to next file, and follow no.2.

I hope it’s clear.
I would appreciate any help.

Thanks,
Zoltan Kovacs

I doubt that anyone will be able to offer help without knowing more details. At minimum, it would help to know the name of the database application and the version of Mac OS that it runs in.

– Rob

Zoltan,
Before getting to any AppleScript, let me know if this describes what you need.

  1. Program asks user to name the folder with the modified files.

  2. Program asks user to name the folder containing all of the folders and files from which the modified files originallly came.

  3. Loop over names of files from step 1.

3a. Try to find a file with the same name somewhere in the folder from step 2 (descend into folders, if necessary)

3b. If a file is found, copy the file from the step 1 folder into the step 2 folder (or into a folder under it)

– End loop 3.

Mike

Mike,

First of all, thank you for your attention.

The algorythm you wrote is exactly what I need!

Just one thing to be more precise: it is important to copy the original file to the >>same<< subfolder. So point 3b. should look like this:

3b. If a file is found, copy the file from the step 1 folder into the step 2 folder (or into a SUBFOLDER UNDER IT WHERE THE FILE FOUND, OVERWRITING THE FILE)

3c. DELETE ORIGINAL FILE FROM STEP 1

I need point 3c to know which files (from step 1) were not found in the original folder (from step 2)

To answear Rob’s question:

  1. The platform is Mac OS 9.

  2. Sorry, it was a bit misleading to write that we use a picture database, because the “database” is simply a set of EPS files placed in a folder with subfolders. So there is no application handling these files which the applescript should communicate with.

:slight_smile: Thank you for any help in advance!

Zoltan

Zoltan,
I had an applescript which did pretty much the reverse of what you needed. So I have messed around with it and came up with this:

set promPt to “Choose the folder containing the new files.”
set fromF to ¬
(choose folder with prompt promPt) as text

set promPt to “Choose the highest level folder containing the original files.”
set toF to ¬
(choose folder with prompt promPt) as text

sweepFiles(fromF, toF)

on sweepFiles(fromFolder, toFolder)
local fromFolder, toFolder
local J, moveIt, iI, L, I, im, M, n
local shortfromName, shorttoName
set L to (list folder fromFolder without invisibles)

set M to (list folder toFolder without invisibles)
repeat with im in M
	set n to im
	
	if folder of (info for file (toFolder & n)) is true then
		sweepFiles(fromFolder, toFolder & n & ":")
	else
		repeat with iI in L
			set I to iI
			set text item delimiters to ":"
			set shortfromName to last text item of fromFolder & I
			set shorttoName to last text item of toFolder & n
			
			if shortfromName is shorttoName then
				--moveFile(fromFolder, I, toFolder)
				try
					tell application "Finder"
						move file (fromFolder & I) to folder toFolder replacing yes
					end tell
				on error e number n partial result p from f to t
					error e number n partial result p from f to t
				end try
				
				exit repeat
			end if
		end repeat
	end if
	
end repeat

end sweepFiles

You will need to copy it into the paste buffer, open AppleScript, paste it into a new window, click on check syntax, and save the file (move_eps_files ??). You can run it by clicking Run right there from the applescript editor. Or you can save it as the appropriate kind of file (i think compile script will work).

Anyway, please test it by making a folder with some files in it and a set of folders with files by the same name into which the files should be moved. I tested it according to my understanding of what you need, but we should be careful. Also, I tested it on OS X.

I can change the REPLACE operation with 1. move the original file to a slightly different name, and then 2. move the new file into the original folder. This might be a good approach until you are confident that it works correctly.

Let me know how dangerously you want to live.
Mike

Thanx much!

I will try it !

Hi All!

Mike’s script worked well, i could spare a lot of work using it. Thanks a lot, Mike!

I used it for a structure of folders with more than ten thousands of items with 18 Gbyte, and the script had to find and replace about 800 EPS files. It was running on an Imac, and, concerning that the script goes through all of the subfolders of the target folder, it was really a long running time (about 10 hours or so), but it was not problem for me because i need this process twice a year when we finish a brochure.

Tjk! I cannot help you because i’m also a beginner in making applescripts but i think if you have to use the script more often, the long running time would be a problem for you. I just have an idea of using Scherlok application in the script to locate the target files in a fast way reducing the running time. :wink:

Zoltan