How can I check for modified Quark documents in all subfolders?

I have created a script which scans a folder and all of its nested subfolders for Quark docs with new modifications dates. It is running on a folder with hundreds of nested folders and it seems to work fine but I was wondering if there was a quicker way to check a folder and its subfolders for new/modified docs.

Is there a way (perhaps apple events) to identify files added to a folder/subfolder without looking through each folder but rather checking the first outer folder for changes?

Here is the basic part of the script that finds the new/repl quark docs (which I put toghether from a looking at a variety of examples here.)

on moveFilesFrom(thisFolder)
	tell application "Finder"
		set date_stamp to (current date) - (8.0 * hours)
		set filesToMove to every file of thisFolder

		repeat with aFIle in filesToMove
			set file_info to file type of (info for (aFIle as alias))

			if file_info = "xprj" or file_info = "xdoc" then
				set mod_date to modification date of (info for (aFIle as alias))

				if mod_date is greater than date_stamp then
					duplicate aFIle to folder "testfolder" of folder "Local desktop" of disk "scratch" with replacing
					my QuarkPDF()
				end if
			end if
		end repeat

		set subFolders to (every folder of thisFolder)
		repeat with aFolder in subFolders
			my moveFilesFrom(aFolder)
		end repeat
	end tell
end moveFilesFrom

Thanks

There are several optimizations you can try here. How effective they’ll be, though, depends somewhat on the number of files in the folder.

The first problem I can see is that you say:

	set file_info to file type of (info for (aFIle as alias))
	
	if file_info = "xprj" or file_info = "xdoc" then ¬
		set mod_date to modification date of (info for (aFIle as alias))
	if mod_date is greater than date_stamp then ¬
		-- do something

So you’re getting ‘info for (aFile as alias)’ and checking the file’s type against a list of wanted types. Then you re-run 'info for (aFile as alias) to check the file’s date.

Depending on the number of new vs. old files in the folder, you might be able to speed this up significantly just by reversing these checks.

For example, assume there’s 1,000 ‘xdoc’ files in the folder, 10 of which are new. You run 2000 ‘info for…’ commands - 1000 to get the file types, and then another thousand to check the date.
Reversing these checks mean you run 1010 checks - 1000 to check the dates, and then 10 more to check the file type of the ten new files. That’s almost a 50% speed increase right there.

However, again depending on the number of files, it might be just quicker to have the Finder check for all new files, then work out which of these are XPress docs:

set date_stamp to (current date) - (8 * hours)
tell application "Finder"
	set newFiles to every file of entire contents of thisFolder whose modification date is less than date_stamp
	-- now you have a list of all new files, so check their types:
	repeat with eachFile in newFiles
		if file type of eachFile is in {"xdoc", "xprj"} then
			duplicate eachFile to folder "testFolder" of folder "Local Desktop" of disk "scratch" with replacing
			my QuarkPDF()
		end if
	end repeat
end tell

Note that using ‘entire contents’ covers all subfolders, so you don’t need to be recursive. This can be faster, but can also be slower if there’s many, many files in many folders.

Note also how I check for valid file types. Checking they’re in a list is faster than checking 'if file_type is “xdoc” or file_type is “xprj”. Also, make sure the list is ordered so that the commonest file type is listed first - the check will return true on the first match, so make sure you match as many files as soon as you can.

Hope that gives you a few pointers.