Help with listing folders and identifying images

Can anyone tell me what I’m doing wrong in the following script… I’m trying to get the contents of a folder (and it’s sub folders) into a list and then identify the binary eps files. Once I’ve done this, I’m trying to get the list of only the binary eps files and write that to a text file.

The part of the script that checks the encoding of the file is correct (using SatImage) but I can’t get the listing operations to work at all. Any help would be greatly appreciated, my boss is hoping I’ll have this finished soon…

[code]on run
set theFolders to choose folder
set LogFile to a reference to (path to desktop as string) & “Binary EPS Report”
set savedTextItemDelimiters to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {return}
set foo to “”
repeat with i in (theFolders as list) – in case multiple objects dropped on applet
if folder of (info for i) then – if object is a folder process its contents too
tell application “Finder” to set foo to foo & entire contents of (i) & return as list
end if
end repeat
set bar to “”

repeat with ii from 1 to count foo
	set iii to (item ii of foo)
	if kind of (info for iii) = "Adobe Photoshop EPS File" then

–check encoding of file with satimage
set ImageData to find text “%ImageData: [ [:digit:]]{1,} "beginimage"” in iii with regexp
set {ASTID, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, space}
set Encoding to text item 8 of matchResult of ImageData
set AppleScript’s text item delimiters to ASTID
– return Encoding
if Encoding = “1” then
tell application “Finder” to set bar to bar & iii & return as text
end if
–end check encoding
end if
end repeat
try
open for access file LogFile with write permission
set eof of file LogFile to 0
write bar to file LogFile
close access file LogFile
on error errText number errNum
close access file LogFile
display dialog errText
end try
set AppleScript’s text item delimiters to savedTextItemDelimiters
end run[/code]

Hi, designermonkey.

foo starts out as text, and AppleScript’s text item delimiters as {return}. When you concatenate the entire contents of a folder to foo, the entire contents are coerced to text too, the individual items being delimited by returns. Coercing that to list produces a one-item list containing that text.

From the syntax you’re using later, I’d guess you actually need aliases to the individual files:

	set theFolders to choose folder
	set LogFile to a reference to (path to desktop as string) & "Binary EPS Report"
	set foo to {} -- We'll be creating a list.
	repeat with i in (theFolders as list) -- in case multiple objects dropped on applet 
		if folder of (info for i) then -- if object is a folder process its contents too 
			tell application "Finder"
				try
					set foo to foo & ((files of entire contents of i) as alias list)
				on error
					set foo to foo & ((files of entire contents of i) as alias)
				end try
			end tell
		end if
	end repeat

You’re a star, worked perfectly…

I didn’t realise I could do an alias list! I know now though!

Thanks

It’s only a Finder thing, for returning aliases instead of Finder references. It errors if there’s only one item to return, which is the reason for the ‘try’ block in the script.