Moving the contents of a folder with Applescript

The idea here is that the script tells the finder to move ‘every file’ in the folder. It then gets a list of every folder inside the current folder and calls itself. This will repeat through all subfolders until all files are moved.

It doesn’t rely on any kind of object selection in the Finder, so it can run quietly in the background while the user is performing other tasks - something you can’t do it you’re trying to move the selected item in the Finder.

tell application "Finder"
    set sourceFolder to folder "MOVE ME" -- of disk "blah", etc.
    my moveFilesFrom(sourceFolder)
end tell

on moveFilesFrom(thisFolder)
    tell application "Finder"
        set filesToMove to every file of thisFolder
        repeat with aFIle in filesToMove
            move aFIle to folder destFolder
        end repeat
        set subFolders to (every folder of thisFolder)
        repeat with aFolder in subFolders
            my moveFilesFrom(aFolder)
        end repeat
    end tell
end moveFilesFrom

(Ray Barber)

An easier way to do this if you don’t need fine control, is to use the “entire contents” phrase:

tell application "Finder"
	set theFolder to path to documents folder from user domain
	set targetFolder to path to pictures folder from user domain
	move entire contents of theFolder to targetFolder
end tell

This operation is MUCH faster, too, since you’re only sending one real command to the Finder.