5

我一直在尝试制作一个脚本来将文件夹中的每个文件移动到根文件夹以包含每个子文件夹。我不想创建一个新文件夹,只需将其移动到根文件夹即可。

我希望能够选择文件夹,然后仅在该特定文件夹上完成操作。

原因是为了组织,我的确切情况是我有超过 TB 的电影,并且文件夹中的文件夹中有文件。我想要根文件夹中的所有这些文件,以便我可以按照我认为合适的方式组织它们。此外,我想复制和删除而不是移动,因为研究让我相信这是最好的路线。

好吧,我无法让脚本正常工作,但我确实找到了一个指向工作流的链接,该工作流正是我正在寻找的:

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


我在上面更新了保留此部分以用于历史记录,此虚线之间的所有内容都是我在编辑后将删除的内容

我试图在下面对这个脚本进行逆向工程,但我发现它无法让它像我想要的那样工作。任何和所有的帮助都会非常感激,我对脚本非常陌生,而且我已经陷入困境。

第二次尝试告诉应用程序“finder”将 main_folder 设置为(选择带有提示“选择主文件夹”的文件夹)将 sub_folders 设置为 main_folder 的文件夹重复 sub_folders 中的 each_folder 将(每个文件夹的每个文件)移动到 main_folder 并替换 end repeat try end try end告诉

第一次尝试告诉应用程序“Finder”将 sourceFolder 设置为文件夹“MOVE ME”——磁盘“blah”等。我的 moveFilesFrom(sourceFolder) end tell

on moveFilesFrom(thisFolder) 告诉应用程序“Finder”设置 filesToMove 到 thisFolder 的每个文件与 filesToMove 中的 aFIle 重复将 aFIle 移动到文件夹 destFolder end repeat 将 subFolders 设置为(thisFolder 的每个文件夹)在 subFolders 中使用 aFolder 重复 my moveFilesFrom(aFolder) end repeat end 告诉 end moveFilesFrom

当我在包含大量信息和子文件夹的文件夹上使用它时,查找器超时,我昨天在测试文件夹上使用了它,它可以正常工作,但要小得多。

我现在正在使用 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

4

3 回答 3

1

你可以尝试这样的事情:

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

或者您可以使用 Lri 建议的 shell 脚本:

set myFolder to quoted form of (choose folder with prompt "choose the main folder")'s POSIX path
do shell script "cd " & myFolder & "; find . -type f -exec mv {} " & myFolder & " \\;"
于 2012-09-09T13:15:26.753 回答
1

一个快速的递归子程序将处理这个问题:

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

如果您想完成其他事情(例如,删除空子文件夹、仅移动特定类型的文件等),这很容易修改。让我知道它是否需要调整。

于 2019-07-06T18:02:50.743 回答
0

文件夹有一个entire contents属性:

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

你也可以find在 shell 中使用:

cd ~/Movies/Folder/; find . -type f -exec echo mv '{}' . \;
于 2012-09-09T13:18:18.603 回答