AppleScript的:创建文件夹/子文件夹和移动多个文件 [英] Applescript: Create folders/subfolders and move multiple files
问题描述
我有一个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 /内容/显示文件夹中。
The file ttu_collectionname_000001.pdf would be moved to the ttu_collectionname_000001/content/display folder.
文件 ttu_collectionname_000001.csv 将被移动到 ttu_collectionname_000001 /元/显示器文件夹中。
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屋!
- 内容结果