【问题标题】:How to move items to folder based on first three characters of file Mac如何根据文件 Mac 的前三个字符将项目移动到文件夹
【发布时间】:2020-09-18 03:15:39
【问题描述】:

我正在尝试移动文件,例如

68 - Logo - Standard (B&W).pdf

到相应的文件夹,类似于

68 - Oak Hill xyz

这些文件夹位于排序后的徽标文件夹中,其中所有文件夹都在一个列表中,如

68 - Oak Hill Xyz 284 - Juniata Hill Xyz 294 - Highland Hill xyz

我找到了不同 AppleScript 的多个版本来完成此操作,但当我尝试它们时,它们似乎已经过时或不再正常工作。我也试过这个终端脚本无济于事。

find . -type f -name “*pdf” -maxdepth 1 -exec bash -c 'mkdir -p “${0%%-*}”’ {} \; \ -exec bash -c 'mv "$0" "${0%%_*}"' {} \;

这些 pdf 文件也位于与相应编号的文件夹不同的文件夹中。

【问题讨论】:

  • 你能提供更多关于文件夹结构的细节吗?
  • 当然。我想将这些文件放入的文件夹位于 Downloads > Logos > Sorted Logos 下。我需要移动的文件位于“下载”>“徽标”>“BW PDF”下。

标签: macos applescript finder


【解决方案1】:

这应该做你想做的(做一些假设......):

property destination_folders : "/Users/<your name>/Downloads/Logos/BW PDF"

set files_to_sort to choose file with multiple selections allowed

tell application "System Events"
    repeat with a_file in files_to_sort
        set prefix to text 1 through 3 of (get name of a_file)
        set destination to my folderStartingWith(prefix)
        if destination is not false then
            move a_file to destination
        end
    end repeat
end tell

on folderStartingWith(txt)
    tell application "System Events"
        try
            set target_folder to first folder of folder destination_folders whose name begins with txt
        on error errstr
            display dialog errstr
            return false
        end try
        return target_folder
    end tell
end folderStartingWith

只需在第一行中替换您的用户名,运行脚本,然后在出现的对话框中选择您要处理的文件。这将显示一条错误消息并跳过任何没有相应文件夹的文件。

这不遵循文件夹层次结构(尽管可以修改为这样做)。如果这是您必须经常做的事情,它也可以改编成 droplet、文件夹操作或查找器服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 2022-01-09
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    相关资源
    最近更新 更多