Applescript:创建文件夹/子文件夹并移动多个文件 [英] Applescript: Create folders/subfolders and move multiple files

查看:47
本文介绍了Applescript:创建文件夹/子文件夹并移动多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Applescript 问题,它比我能构建的要复杂得多.这两天一直在找,找不到这样的剧本,也找不到足够的资料,以我有限的知识拼凑起来.

I have an Applescript question that is much more complex than I can construct. I have been searching for the past couple of days, and I cannot find any script like this, nor can I find enough information to piece one together with my limited knowledge.

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

I have multiple files with structured names. Each file has the following name structure:

ttu_collectionname_000001.pdf
ttu_collectionname_000002.mp3
ttu_collectionname_000003.pdf ...等(这些文件中的每一个都是不同的文件类型.)

ttu_collectionname_000001.pdf
ttu_collectionname_000002.mp3
ttu_collectionname_000003.pdf ... etc. (Each of these files are of varying file types.)

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

There is also a csv metadata file associated with each of the original files.

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

ttu_collectionname_000001.csv
ttu_collectionname_000002.csv
ttu_collectionname_000003.csv ... etc. (Each of these files are csv files.)

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

I need to create a folder based on the name of the file with sub and sub-subfolders. Each top-level folder name will be unique in the number sequence. Each sub and sub-subfolder name will be the same for each top-level folder.

文件夹结构应如下所示:

The folder structure should look like this:

  • ttu_collectionname_000001
    • 内容
      • 存档
      • 显示
      • 存档
      • 显示
      • 内容
        • 存档
        • 显示
        • 存档
        • 显示

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

        I then need to move the each file to a particular sub-subfolder.

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

        The file ttu_collectionname_000001.pdf would be moved to the ttu_collectionname_000001/content/display folder.

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

        The file ttu_collectionname_000001.csv would be moved to the ttu_collectionname_000001/metadata/display folder.

        推荐答案

        尝试:

        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
        

        这篇关于Applescript:创建文件夹/子文件夹并移动多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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