0

我有一个 Applescript 问题,它比我能构建的要复杂得多。这几天我一直在寻找,我找不到任何这样的脚本,也找不到足够的信息来拼凑我有限的知识。

我有多个具有结构化名称的文件。每个文件具有以下名称结构:

ttu_collectionname_000001.pdf
ttu_collectionname_000002.mp3
ttu_collectionname_000003.pdf ... 等等(每个文件都有不同的文件类型。)

还有一个与每个原始文件关联的 csv 元数据文件。

ttu_collectionname_000001.csv
ttu_collectionname_000002.csv
ttu_collectionname_000003.csv ... 等等(这些文件都是 csv 文件。)

我需要根据带有子和子子文件夹的文件名创建一个文件夹。每个顶级文件夹名称在编号序列中都是唯一的。对于每个顶级文件夹,每个子文件夹和子文件夹的名称都相同。

文件夹结构应如下所示:

  • ttu_collectionname_000001
    • 内容
      • 档案
      • 展示
    • 元数据
      • 档案
      • 展示
  • ttu_collectionname_000002
    • 内容
      • 档案
      • 展示
    • 元数据
      • 档案
      • 展示

然后我需要将每个文件移动到特定的子文件夹。

文件ttu_collectionname_000001.pdf将被移动到ttu_collectionname_000001/content/display文件夹。

文件ttu_collectionname_000001.csv将移动到ttu_collectionname_000001/metadata/display文件夹。

4

2 回答 2

2

尝试:

set myFolder to "Mac OS X:Users:stark:Main Folder"
tell application "Finder" to set myFiles to folder myFolder's files as alias list
repeat with aFile in myFiles
    tell application "System Events" to set {fileName, fileExt} to {name, name extension} of aFile
    set baseName to text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
    do shell script "mkdir -p " & (quoted form of (POSIX path of myFolder)) & "/" & baseName & "/{\"content\",\"metadata\"}/{\"display\",\"archive\"}"
    tell application "System Events"
        if fileExt is "pdf" then move aFile to (myFolder & ":" & baseName & ":content:display" as text)
        if fileExt is "csv" then move aFile to (myFolder & ":" & baseName & ":metadata:display" as text)
    end tell
end repeat
于 2013-01-25T18:51:25.063 回答
0

假设您的文件在同一个文件夹中, 前

这个 AppleScript:

set pathToFolderOfTTUFiles to (path to the desktop as text) & "TTU:"
tell application "Finder"
    set theFiles to every item of folder pathToFolderOfTTUFiles whose name extension is not "csv" and kind is not "Folder"
    repeat with theFile in theFiles
        set lengthOfExtension to (length of (theFile's name extension as text)) + 1
        set fileNameWithoutExtension to text 1 through -(lengthOfExtension + 1) of (theFile's name as text)
        set theFolder to make new folder at folder pathToFolderOfTTUFiles with properties {name:fileNameWithoutExtension}

        set theContentFolder to make new folder at theFolder with properties {name:"content"}
        make new folder at theContentFolder with properties {name:"archive"}
        set theContentDisplayFolder to make new folder at theContentFolder with properties {name:"display"}
        set theMetadataFolder to make new folder at theFolder with properties {name:"metadata"}
        make new folder at theMetadataFolder with properties {name:"archive"}
        set theMetadataDisplayFolder to make new folder at theMetadataFolder with properties {name:"display"}

        move theFile to theContentDisplayFolder
        set pathToCSV to pathToFolderOfTTUFiles & fileNameWithoutExtension & ".csv"
        if exists pathToCSV then move pathToCSV to theMetadataDisplayFolder
    end repeat
end tell

创建这个: 后

于 2013-01-25T18:47:13.023 回答