Using applescript I want to move each file to a folder in the root folder

I am trying to make a script to move each file to a folder in the root folder to include each subfolder. I do not want the new folder to just move it to the root folder.

I want to be able to select a folder, and then the action will be performed only in that specific folder.

The reason is the organization, my exact situation is that I have over TB films and there are files inside folders in folders. I want all these files to be in the root folder so that I can organize them as I see fit. I would also like to copy and delete instead of moving, as the study prompted me to believe that this is the best route.

Well, I couldn't get the script to work, but I found a link to a workflow that does exactly what I'm looking for:

http://www.macworld.com/article/1160660/automator_filesfromsubfolders.html


I updated above, keeping this section for historical purposes, everything between the dashed lines is what I would delete after editing

I tried redesigning this script below, which I found, but I just can't get it to work the way I want. Any help would be very helpful, I'm very new to scripting, and I came to the rock.

""        main_folder ( " " )        sub_folders main_folder        ​​sub_folders        ( ) main_folder                            end tell

"Finder" sourceFolder "MOVE ME" - "" ..   moveFilesFrom (sourceFolder)  end tell

moveFilesFrom (thisFolder) "Finder" set filesToMove thisFolder aFIle ToMove   aFIle destFolder ( ) aFolder moveFilesFrom (aFolder) end moveFilesFrom

, aa, , , , .

script, adayzdone

    set myFolder to (choose folder with prompt "choose the main folder")
    tell application "Finder"
    set myfiles to get every item of (entire contents of folder myFolder) whose kind ≠ "Folder"
    move myfiles to myFolder
    end tell

+5
3

- :

set myFolder to (path to desktop as text) & "testFolder"
tell application "Finder"
    set myFiles to get every item of (entire contents of folder myFolder) whose kind ≠ "Folder"
    move myFiles to myFolder
end tell

script, Lri:

set myFolder to quoted form of (choose folder with prompt "choose the main folder") POSIX path
do shell script "cd " & myFolder & "; find . -type f -exec mv {} " & myFolder & " \\;"
+2

entire contents:

tell application "Finder"
    set f to choose folder
    move files of entire contents of f to f
end tell

find :

cd ~/Movies/Folder/; find . -type f -exec echo mv '{}' . \;
+1

A quick recursive routine will handle this:

set theFolder to POSIX path of (choose folder with prompt "Choose a folder")

tell application "System Events"
    set theFiles to my recursiveSearch(folder theFolder)
    move theFiles to folder theFolder
end tell

on recursiveSearch(theFolder)
    tell application "System Events"
        set theFiles to every file of theFolder whose visible is true
        set theSubFolders to every folder of theFolder
        repeat with thisFolder in theSubFolders
            set theFiles to theFiles & my recursiveSearch(thisFolder)
        end repeat
        return theFiles
    end tell
end recursiveSearch

This is easy to change if you want to perform other tasks (for example, deleting empty subfolders, moving only certain types of files, etc.). Let me know if you need to configure this.

0
source

All Articles