Applescript:如何从文件名创建新文件夹,创建子文件夹,将文件移动到子文件夹

时间:2016-09-12 15:26:49

标签: macos directory applescript

我想创建一个 applescript应用程序,我可以将文件(例如我的案例中的Illustrator文件)拖到上面,以创建一个新文件夹 原始(Illustrator)文件的名称。我希望在相同位置中创建新文件夹作为Illustrator文件。

接下来,我想在新文件夹中创建3个子文件夹。 (例如,一个名为ff,一个名为mr,一个名称为NX。)

在其中一个已创建的子文件夹中,我想创建另一个子文件夹。 (例如,在ff文件夹中命名为Hires。)

最后,我希望将illustrator文件移动到创建的(mr)子文件夹中。

下面是我想要创建的文件结构的屏幕截图。

Desired file structure

我一直在搞乱一些不同的剧本但是没有任何东西可以按照需要运作。

非常感谢。

1 个答案:

答案 0 :(得分:1)

这是一个利用mkdir shell命令的简单解决方案,该命令能够在一行中创建复杂的文件夹结构。

将脚本另存为应用程序

on open theFiles
    set folderStructure to "/{ff/Hires,mr,NX}"
    repeat with aFile in theFiles
        tell application "System Events"
            set {name:Nm, name extension:Ex} to aFile
            set baseFileName to text 1 thru ((get offset of "." & Ex in Nm) - 1) of Nm
            set baseFolder to POSIX path of container of aFile & "/" & baseFileName
        end tell
        do shell script "/bin/mkdir -p " & quoted form of baseFolder & folderStructure
        do shell script "/bin/mv " & quoted form of POSIX path of aFile & space & quoted form of (baseFolder & "/mr")
    end repeat
end open
相关问题