从 CSV 复制 PDF 和名称作为值并创建文件夹

Copy PDF and name as values from CSV and create folders

我想让自己在组织学生作业时轻松一些。我正在努力想出 Automator/Applescript 中的正确工作流程。

CSV 列表:

PDF 文件:MarkScheme.pdf

这是我希望发生的事情:

  1. 在CSV文件中为每个学生创建一个文件夹,命名为'StudentA'
  2. 将PDF文件复制到每个文件夹中,命名为'MarkScheme-StudentA'

最终文件夹(每个学生)应该如下所示:

 - StudentA
 -- MarkScheme-StudentA.pdf
 - StudentB
 -- MarkScheme-StudentB.pdf
- StudentC
 -- MarkScheme-StudentC.pdf

实现此目标的最佳方法是什么?非常感谢。

下面的 Applescript 可以满足您的需求。

我添加了一些评论以使其清楚:

set FCsv to choose file with prompt "Select your CSV file with students"
set Dest to choose folder with prompt "Select master folder"
set FPDF to choose file with prompt "Select your PDF file"
tell application "Finder" to set PdfName to name of FPDF
set PdfName to text 1 thru ((offset of ".pdf" in PdfName) - 1) of PdfName -- get PDF name without .pdf extension

set Fcontent to read FCsv -- read all cvs file
set FLines to every paragraph of Fcontent
repeat with aStudent in FLines -- loop through each line of the cvs file
tell application "Finder"
    try -- try to create folder Student in master folder : assumption, it does not exist before !
        set SubFolder to make new folder in Dest with properties {name:aStudent}
    end try
    set SFolder to SubFolder as string
    -- use 'cp' shell command to copy with new name
    do shell script "cp " & (quoted form of (POSIX path of FPDF)) & " " & (quoted form of ((POSIX path of SFolder) & PdfName & "-" & aStudent & ".pdf"))
end tell
end repeat