Saturday, December 16, 2017

#1 2007-03-04 12:50:44 am

Kevin Bradley
Administrator
From:: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

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.

Applescript:

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)


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.


Filed under: Finder

Offline

 

#2 2007-03-04 12:52:48 am

Kevin Bradley
Administrator
From:: Independence, MO
Registered: 2006-03-13
Posts: 548
Website

Re: Moving the contents of a folder with Applescript

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

Applescript:

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.


Nitewing '98
--
I distrust morning people, largely because I suspect them of getting together early one day while the rest of us were asleep and setting up the rules of civilization.


Filed under: Finder

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)