traverseDirectory

I thought someone might find this useful. I was looking for a quick way to get info about files in a folder, and it’s subfolders, so I came up with this.

set theDir to choose folder --Choose the folder you want to look in
set directoryFiles to traverseDirectory(theDir) --Call my function

--Just an example of what you can do with it
if directoryFiles is not "" then
	repeat with currentFile in directoryFiles
		display dialog (name of currentFile as string) buttons {"Cancel"} giving up after 1
	end repeat
else
	display dialog "There are no files in this directory!"
end if

(*
	traverseDirectory
	Useage: myTraverseDirectory(path)
	Path: path to a folder or disk
	Returns: list of file references
	Notes: Returns an empty string if you feed it a file or empty folder
*)
on traverseDirectory(theDirectory)
	tell application "Finder"
		if (kind of (info for theDirectory) is in {"Folder", "Volume"}) then
			try
				set theReturn to (files of theDirectory)
			end try
			try
				set thisDirectorysDirectories to folders of theDirectory
				repeat with currentDirectory in thisDirectorysDirectories
					set theReturn to theReturn & my traverseDirectory(currentDirectory)
				end repeat
			end try
		end if
	end tell
	if (theReturn is not {}) then
		return theReturn
	else
		return ""
	end if
end traverseDirectory