Basic Question: Need list of files in directory tree

This may be a simple question, but I have not found any examples as of yet. I need to get a list of files (with full paths) in a directory tree. I have been able to get all sorts of scripts that delete files begining at a certain folder. But I need to keep the files and just get a list. I know this is a simple recursive exercise, but the scripts I have been using don’t give me the list I am looking for:

global fileList
set fileList to {}
– recursive loop
on files2Check(sourceFolder)
tell application “Finder”
set fileList to fileList & every file of sourceFolder
set folderList to every folder of sourceFolder
if number of items in folderList > 0 then
repeat with x in folderList
files2Check(x) of me
end repeat
end if
end tell
end files2Check

– set the import folder
tell application “Finder”
set sourceFolder to choose folder with prompt “select the Source Folder”
on error – no open folder windows
set the sourceFolder to path to desktop folder
end try
end tell
set thefileList to files2Check(sourceFolder)

I had hoped that thefileList would have what I want but it is always blank.

It would do, except for the fact that you:

set thefileList to files2Check(sourceFolder)

and your global variable (where you’re building the list) is called ‘fileList’, not ‘thefileList’.

Match the variable names and you should find it works fine.