【问题标题】:Applescript for creating subfolder and move files, with part of a name用于创建子文件夹和移动文件的 Applescript,带有部分名称
【发布时间】:2013-01-25 23:59:08
【问题描述】:

我一直在寻找这样的脚本,但找不到。我怀疑它类似于this

但不完全是,我不确定如何修改它以适合我。

我有一组这样的多个名称的文件....

文件名 Vyear #01(年份).ext

文件名 Vyear #01(年份).ext

等等,约定总是一样的。

文件名(有时是多个单词)后跟 V 表示版本,然后是括号中的年份,然后是数字,然后是括号中的另一个年份。这很复杂,但这一切都是有原因的。我正在寻找的是一种仅根据该名称的第一部分自动将所有这些文件移动到子文件夹中的方法。所以像这样的文件...

迷雾 V2000 #01 (2011).zip

将被移动到名为 this 的文件夹中。

迷雾V2000

我经常需要制作这样的文件,我希望将它们分类到子文件夹中。我的问题是我不确定如何仅选择名称中的第一个(标题中有两个或三个单词的文件的帐户)和卷号仅用于创建子文件夹,然后匹配移动的文件名.

我希望我能正确解释这一点。如果有人可以提供帮助,我将不胜感激。

干杯。

【问题讨论】:

    标签: applescript filenames move finder


    【解决方案1】:

    试试这个。基本上,如果我们知道“#”字符在文件名中的位置,我们就可以计算文件夹名称。然后我们可以得到所有文本到那里 - 2个字符。然后你只需要创建那个文件夹并将文件移动到其中。简单的。祝你好运。

    set sourceFolder to choose folder
    
    tell application "Finder"
        set theFiles to files of sourceFolder
    
        repeat with aFile in theFiles
            set fileName to name of aFile
    
            if fileName contains "#" then
                set poundOffset to offset of "#" in fileName
                set folderName to text 1 thru (poundOffset - 2) of fileName
    
                set newFolder to (sourceFolder as text) & folderName & ":"
                if not (exists folder newFolder) then
                    make new folder at sourceFolder with properties {name:folderName}
                end if
    
                move aFile to folder newFolder
            end if
        end repeat
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-09
      • 2021-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多