Developing a stay-open queue with lists

Hi guys,

I am having the hardest time trying to make a basic queue system for a hot folder. Basically I have been trying to modify Kevin Meaney’s stay-open folder action script (http://scriptbuilders.net/files/folderactionreplacement1.0.0.html) to process folders full of files in the order that they are dropped into the hot folder.

I am also using this script to give me a list of folders in the hot folder, and files within each folder:

property file_types : {} --file types, set to {} and inc_folders to true to just return folders
property with_subfolders : true --list subfolders or not (recursion)
property inc_folders : false --include folders in the list of files to return

set folderToProcess to choose folder with prompt "Select Folder to process files"
set {the_files, folder_list} to get_folder_list(folderToProcess, file_types, with_subfolders, inc_folders)
set the_files to list 2 of the_files

on get_folder_list(folderToProcess, file_types, with_subfolders, inc_folders)
	set {the_files, folder_list} to {{}, {}}
	tell application "Finder" to set folder_list to get every item of folder folderToProcess
	repeat with new_file in folder_list
		try
			set temp_file_type to file type of new_file
		on error
			set temp_file_type to "fold"
		end try
		--set the_files to the_files & {new_file as string}
		if temp_file_type = "fold" then
			if with_subfolders = true then set the_files to my get_folder_list((new_file as string), file_types, with_subfolders, inc_folders)
		end if
		
	end repeat
	
	return {the_files, folder_list}
end get_folder_list

The problem with this script is that it will return a list of all the folders (excellent!) but will only return a list of the last folder’s files. What I ultimately want to be able to do is have a process enclosed in a repeat loop, where the loop takes the first folder and processes each of the files in it’s list until they are all done. Then the script removes that folder list item and and moves on to the next one, processing the each of the files in the second folder’s list until they are done… then it removes that folder list item and goes on to the next, etc.

Can anybody help with this… I think i am to the point where I have been so consumed with it that my thinking could be totally on the wrong track. Does this sound like a good way to do it? Has anyone seen something like this before?

set allFiles to {}
set {end of allFiles to the_files, folder_list} to get_folder_list(folderToProcess, file_types, with_subfolders, inc_folders)

You’re not accumulating the file lists – you’re resetting the_files for every folder that has files.

Awesome, thank you for the help!!

I see exactly what you are saying, but the logic in your code is not compiling for me. I modified this line in the subroutine’s repeat loop to see if it would yield the same effect:

if with_subfolders = true then set the end of the_files to my get_folder_list((new_file as string), file_types, with_subfolders, inc_folders)

Turns out it gets all the file lists like I want it to, but it wraps them in list after list after list, so I’m now trying to figure out how to pare it down to just one simple list.

Thanks again for the help, it is very appreciated!

This post replaces a reply I made last night.

Hi.

I think this may be what you want. But with your original property values, it returns an empty list, since no file types are specified and ‘inc_folders’ is false!

property file_types : {} --file types, set to {} and inc_folders to true to just return folders
property with_subfolders : true --list subfolders or not (recursion)
property inc_folders : false --include folders in the list of files to return

set folderToProcess to choose folder with prompt "Select Folder to process files"
set the_files to get_folder_list(folderToProcess, file_types, with_subfolders, inc_folders)

on get_folder_list(folderToProcess, file_types, with_subfolders, inc_folders)
	tell application "Finder"
		set file_list to every file of folderToProcess whose file type is in file_types
		if (with_subfolders) or (inc_folders) then
			set folder_list to every folder of folderToProcess
			if (with_subfolders) then
				repeat with this_folder in folder_list
					if (inc_folders) then set end of file_list to this_folder's contents -- ie. 'this_folder' dereferenced.
					set file_list to file_list & my get_folder_list(this_folder, file_types, with_subfolders, inc_folders)
				end repeat
			else -- inc_folders must be true here.
				set file_list to file_list & folder_list
			end if
		end if
		
		return file_list
	end tell
end get_folder_list

Got it working! Thank you guys so much, this was extremely helpful!