0

简而言之,我需要做这样的事情:

  1. 我有一个包含很多文件的文件夹,并且想要处理所有扩展名为 .epub 的文件。
  2. 所有文件都已遵循命名方案:姓氏、名字 - Title.epub 或姓氏、名字 - 系列 x - Title.epub,我需要一个用于姓氏、名字、系列(如果存在)和标题的解析器。
  3. 我有一个设置元数据的命令行工具: ebook-meta filename -a "Firstname Lastname" -t Title

1.) 有很多片段,但是我需要 2.) 的输入,并感谢任何帮助/指针!

4

1 回答 1

1

您可以从以下开始并更改它以满足您的需求。它编译,虽然未经测试。

set p to POSIX file "/Users/kaass/Desktop/test/"
tell application "Finder" to set filelist to name of every file of folder p

repeat with filename in filelist
    set text item delimiters to ""
    if text -5 thru -1 of filename is equal to ".epub" then
        set temp to items 1 thru -6 of filename as text

        set text item delimiters to " - "
        set myWord to text items 1 thru -1 of temp
        set title to myWord's last item as text

        if myWord's length is equal to 3 then set series to myWord's second item as text

        set myWord to item 1 of myWord as text
        if myWord contains "," then
            set text item delimiters to ", "
        else
            set text item delimiters to " "
        end if
        set author to (text item 2 of myWord) & space & (text item 1 of myWord)
        set path_and_filename to POSIX path of file p & filename
        do shell script "echo Processing file " & quoted form of path_and_filename & ": " & author & " +++ " & title
        do shell script "/Applications/calibre.app/Contents/MacOS/ebook-meta " & quoted form of path_and_filename & " -a " & quoted form of author & " -t " & quoted form of title
    end if
end repeat

如果您需要更改某些内容,请发表评论。

于 2011-12-02T00:09:15.707 回答