Extracting path info...

I need a script where you can choose a folder and the script will search through it for sub folders (there will be several) called ‘Photography’ and list all files with .tif in their names.

My script so far is:

set theFolder to choose folder with prompt “Select the folder to check”
set FileList to {}

tell application “Finder”
set folderList to (folders of entire contents of theFolder)
repeat with currentFolder in folderList
if name of currentFolder is “Photography” then
set FileList to FileList & (files of currentFolder whose name contains “.tif”)
end if
end repeat
end tell

And this returns:
{file “file.tif” of folder “Photography” of folder “folder 3” of folder “test folder” of application “Finder”, file “pic.tif” of folder “Photography” of folder “folder 3” of folder “test folder” of application “Finder”, file “test.tif” of folder “Photography” of folder “folder 2” of folder “test folder” of application “Finder”, file “test2.tif” of folder “Photography” of folder “folder 2” of folder “test folder” of application “Finder”}

Now I need that information in a more helpful format, preferably full path names for each .tif file, but I can’t seem to extract that.

What am I doing wrong, any ideas?

TIA,
Emma

This gives you aliases:
set FileList to FileList & ((files of currentFolder whose name contains “.tif”) as alias list)

This gives you text paths:
set FileList to FileList & ((files of currentFolder whose name contains “.tif”) as string)

This will give you a list of aliases:

set theFolder to choose folder with prompt "Select the folder to check"
set FileList to {}

tell application "Finder"
	set folderList to folders of entire contents of theFolder whose name is "Photography"
	repeat with currentFolder in folderList
		try
			set FileList to FileList & ((files of currentFolder whose name extension is "tif") as alias list)
		on error number -1700 -- there's a stupid longstanding Finder bug where the 'as alias list' coercion fails when there's only one item referenced, so kludge around it here
			set end of FileList to (files of currentFolder whose name extension is "tif") as alias
		end try
	end repeat
end tell

If you need posix paths rather than aliases, add the following:

repeat with itemRef in FileList
	set itemRef's contents to POSIX path of itemRef
end repeat

HTH

has

p.s. FWIW, if the Finder’s scripting support were a bit more robust, you could do the whole lot in a one-liner:

tell application "Finder"
    set FileList to ((files whose name extension is "tif") of (folders whose name is "Photography") of entire contents of theFolder) as alias list
end tell

p.p.s. Ironically, the Finder actually handles ‘as alias’, ‘as file specification’, etc. coercions perfectly well, e.g. ‘manyFoldersRef.get(type=k.Alias)’ works fine in Python. It’s actually AppleScript that screws up ‘manyFoldersRef as alias’, but instead of fixing that bug they bodge a semi-broken workaround into Finder instead, so now there’s two bugs instead of none!