使用 applescript 我想将文件夹中的每个文件移动到根文件夹 [英] Using applescript I want to move every file within the folder to the root folder

查看:36
本文介绍了使用 applescript 我想将文件夹中的每个文件移动到根文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been trying to make a script to move every file within a folder to the root folder to include every sub folder. I don't want to make a new folder just move it to the root folder.

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

I want to be able to select the folder and then the action be completed on that specific folder only.

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

The reason is for organization, my exact situation is I have over a TB of movies and there's files within folders within folders. I want all those files on the root folder so that I can organize them how I deem fit. Also I would like to copy and delete instead of move as research has led me to believe is the best route.

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

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

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

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

我已经尝试对下面的这个脚本进行逆向工程,我发现但是,我无法让它像我想要的那样工作.任何和所有帮助都会非常感谢,我对脚本编写非常陌生,而且我已经遇到了困难.

I have tried to reverse engineer this script below, that i found but, I just can't get it to work like I want to. Any and all help will be much apprieciated, I am very new to scripting and I have come to a rock.

第二次尝试告诉应用程序发现者"将 main_folder 设置为(选择带有提示选择主文件夹"的文件夹)将 sub_folders 设置为 main_folder 的文件夹重复 sub_folders 中的 each_folder移动(each_folder 的每个文件)到 main_folder 并替换结束重复尝试结束尝试最后告诉

2nd Attempt tell application "finder" set main_folder to (choose folder with prompt "choose the main folder") set sub_folders to folders of main_folder repeat with each_folder in sub_folders move (every file of each_folder) to main_folder with replacing end repeat try end try end tell

第一次尝试告诉应用程序查找器"将 sourceFolder 设置为文件夹MOVE ME"——磁盘blah"等.我的 moveFilesFrom(sourceFolder)最后告诉

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

on moveFilesFrom(thisFolder)告诉应用程序查找器"将 filesToMove 设置为 thisFolder 的每个文件用 filesToMove 中的 aFile 重复将文件移动到文件夹 destFolder结束重复将子文件夹设置为(此文件夹的每个文件夹)重复子文件夹中的文件夹我的 moveFilesFrom(aFolder)结束重复结束告诉结束移动文件来自

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

当我在包含大量信息和子文件夹的文件夹中使用它时,查找程序超时,我昨天在一个测试文件夹中使用了它,它没有问题,但体积要小得多.

我现在正在使用 adayzdone 提供的这个脚本

I am now using this script provided by 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

<小时>

推荐答案

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

A quick recursive subroutine 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 modify if you want to accomplish other things (e.g., deleting the empty subfolders, moving only specific kinds of files, etc). Let me know if it needs tweaking.

这篇关于使用 applescript 我想将文件夹中的每个文件移动到根文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆