Folder confusion - moving files

Hi everyone.

I am trying to write a script that will accept a folder as an input, process a series of files that have the correct file type, and then move the processed files to the new folder. This works fine if the script needs to create the new folder, but I don’t understand enough about how to reference folders to get it to work if the subfolder already exists. Here is the code:

property ExtensionsList : {"doc", "docx"}

on run
	display dialog "Process files from the folder of your choice."
	tell application "Finder"
		set the source_folder to (choose folder with prompt "Pick the folder containing the documents to process:")
		set newFolderName to source_folder's name & "- Old Versions"
		set these_documents to (every item of the source_folder whose name extension is in the ExtensionsList) as list
		set numDocs to the count of these_documents
		if (exists folder newFolderName of source_folder) is false then
                        -- THIS WORKS FINE
			set newFolder to make new folder at source_folder with properties {name:newFolderName}
                        -- CANNOT FIGURE OUT WHAT SHOULD GO HERE... need to reference the folder later, below... 
			set newFolder to alias newFolderName
		end if
		repeat with i from 1 to numDocs
                    -- DOCUMENT PROCESSING

			tell application "Finder"
				move this_item to newFolder                 -- BROKEN WHEN newFolder is not created by the script
			end tell
               end repeat
       end tell
end run

If someone could help, I would be very appreciative. If you can also explain in some more general way how files and folders are referenced, or point me to an article that explains it (i.e., when should one use an alias vs. a posix path vs. a name) I would also be very grateful.


I am not really testing your code but it seems to me that you should:

# change this:
			set newFolder to alias newFolderName
# into this:
			set newFolder to folder newFolderName of source_folder


Thank you both so much!

That works great.