moving files from a text list

Have been plotting along slowly with this one. Still can’t get it to work, and worse…don’t know why. I am trying to read a text doc. setting it’s contents to a list, then using that list to filter through a set of files in one folder and moving that target set of files to another folder. Here’s the script:
with timeout of 600 seconds
tell application “Finder”

	--------------------------------------------------------------------
	-- SET FOLDERS
	set myfolder to choose folder with prompt "IMAGE FILES?"
	set myfiles to (every file of folder myfolder whose name does not start with "." and (file type is in {"TIFF", "JPEG"} or name extension is in {"tiff", "tif", "jpeg", "jpg"}))
	set dstfolder to choose folder with prompt "DESTINATION FOLDER?"
	----------------------------------------------------------------------
	
	--GET TEXT DOC INTO LIST FORM FOR COMPARISON TO FOLDER FILES
	set aFile to (choose file with prompt "Select a file to read:" without invisibles)
	open for access aFile
	set txt to (read aFile)
	close access aFile
	
	set mylist_1 to {}
	set para to paragraphs of txt
	
	--Copy Text file to new list
	repeat with aP in para
		if (count aP) ≠ 0 then copy aP to end of mylist_1
	end repeat
	
	------------------------------------------------------------------------------------------------------------------------------
	--START PROCESS
	-- Puts every file in a selected folder into a list
	repeat with i from 1 to number of items in mylist_1
		move item i of myfolder to dstfolder
	
	end repeat
	------------------------------------------------------------------------------------------------------------------------------
	
end tell

end timeout

Hi,

maybe like this?

set myfolder to choose folder with prompt "IMAGE FILES?"
set dstfolder to choose folder with prompt "DESTINATION FOLDER?"
set aFile to (choose file with prompt "Select a file to read:" without invisibles)
open for access aFile
set filesToMove to paragraphs of (read aFile)
close access aFile

tell application "Finder"
	
	move (every file of folder myfolder whose name does not start with "." and name is in filesToMove and (file type is in {"TIFF", "JPEG"} or name extension is in {"tiff", "tif", "jpeg", "jpg"})) to dstfolder
end tell

D.

Hi DE,

your script just moves some (filtered image) files from myfolder to destfolder.
The number of paragraphs in the text file specifies the number of files to be copied, nothing else
What do you want to filter and what kind of information is in the text file?

Thanks for the reply. Happy New Year!. I am exporting a reference of files (.jpeg, .tiff) from a database in .csv format. I have a folder that contains these real source files (.jpg,.tiff) I want to export out of my database a list of files to be moved to certain folders.

Example: database to export all hi_res files that are landscape in orientation. This .csv file should now be used to move the target files to the proper folder. Sound do-able?

My problem is that I have over 6000 image files and a script is my best bet. On my machine (G4 laptop 1.87mhz Os X 10.4.8) it takes about 30 seconds to get a list and then it hangs for the full 10 minutes and then produces no results.

Any thoughts?

Hi DE,

it would be helpful to have a few lines of the .csv-file
and the condition(s), which files should be copied in which folders.
Most likely it’s possible to do that with AppleScript

I second StefanK’s request. Since the format of the csv file serving as the director of the moves is probably consistent throughout, it is relatively straight-forward to parse the file a paragraph at a time and direct the moves. Among the “conditions” Stephan mentions are do you want to leave the original where it was or delete it from the source folder? To move all hi-res landscape files presumes that the csv master list includes this information - does it - or is it necessary to extract that info from the metadata for each file?

Thanks guys. Here is an example of what the .csv file looks like:

adv.001.jpg
adv.002.jpg
adv.003.jpg
mus.001.jpg
mus.002.jpg
mus.017.jpg
mus.019.jpg

The conditions for attatining this list is done prior to the export of the .csv so I don’t need to handle it with aplescript.

What I need is to read the above .csv file (which my script does)
Read an image folder that contains the actual “.jpg files” (my script does this)
Target a destination folder to send (all the files listed in the .csv file) from the images folder to the target folder (script does not do this)

Here is the script again:

with timeout of 600 seconds
tell application “Finder”

    --------------------------------------------------------------------
    -- SET FOLDERS
    set myfolder to choose folder with prompt "IMAGE FILES?"
    set myfiles to (every file of folder myfolder whose name does not start with "." and (file type is in {"TIFF", "JPEG"} or name extension is in {"tiff", "tif", "jpeg", "jpg"}))
    set dstfolder to choose folder with prompt "DESTINATION FOLDER?"
    ----------------------------------------------------------------------
    
    --GET TEXT DOC INTO LIST FORM FOR COMPARISON TO FOLDER FILES
    set aFile to (choose file with prompt "Select a file to read:" without invisibles)
    open for access aFile
    set txt to (read aFile)
    close access aFile
    
    set mylist_1 to {}
    set para to paragraphs of txt
    
    --Copy Text file to new list
    repeat with aP in para
        if (count aP) ≠ 0 then copy aP to end of mylist_1
    end repeat
    
    ------------------------------------------------------------------------------------------------------------------------------
    --START PROCESS
    -- Puts every file in a selected folder into a list
    repeat with i from 1 to number of items in mylist_1
        move item i of myfolder to dstfolder
    
    end repeat
    ------------------------------------------------------------------------------------------------------------------------------
    
end tell

end timeout

if the text in the .csv-file is only a list of filenames,
then you can copy the files with this

--------------------------------------------------------------------
-- SET FOLDERS
set myfolder to choose folder with prompt "IMAGE FILES?"
tell application "Finder" to set myfiles to (every file of folder myfolder whose name does not start with "." and (file type is in {"TIFF", "JPEG"} or name extension is in {"tiff", "tif", "jpeg", "jpg"}))
set dstfolder to choose folder with prompt "DESTINATION FOLDER?"
----------------------------------------------------------------------

--GET TEXT DOC INTO LIST FORM FOR COMPARISON TO FOLDER FILES
set aFile to (choose file with prompt "Select a file to read:" without invisibles)
set para to paragraphs of (read aFile)

--Copy every file which name is in text file to dstfolder
repeat with aP in para
	with timeout of 600 seconds
		try
			tell application "Finder" to copy (get file aP of folder myfolder) to dstfolder
		end try
	end timeout
end repeat

PS: the timeout block is actually only needed, if copying one file takes more than 2 minutes
and the try block avoids error messages e.g. if a file doesn’t exist in the source folder

I thought the OP wanted to filter out things like hi-res and orientation. Here’s how you get those:

set f to choose file without invisibles
tell application "Image Events"
	set I to open f
	set P to {dimensions, resolution} of I
end tell

In compressed form:

tell application "Image Events" to set P to {dimensions, resolution} of (open (my (choose file without invisibles))) -- where choose file is replaced with an alias to the image

thanks again guys. Stefan I ran your script ( itook 23 minutes on my machine) however, it never copied anything. The event log showed that every file was being processed, see a segment of the log below:

	document file "wrk.124.jpg" of folder "Master_Previews" of folder "previews" of folder "12.25.06" of folder "DB of Measurements" of folder "Desktop" of folder "de" of folder "Users" of startup disk

However nothing copied. And since I have 6000 files to go through is 23 minutes about right?

Sorry, my fault.
Change copy to move in this line:

tell application "Finder" to move (get file aP of folder myfolder) to dstfolder

Hi Stephan,

where is the advantage/difference of your solution to the script I posted above (http://bbs.applescript.net/viewtopic.php?pid=72192#p72192)? I’d rather think a repeat loop will make things going slower … :wink:

D.

Hi Dominik,

I have to admit, that I read your script not very intensly, because DE
didn’t respond to it. Indeed your script is much better, you can even make it
two lines shorter. The open and close lines are not necessary :wink:

PS: in this case speed doesn’t matter, because the copy process takes much more time than the repeat loop