Applescript-将文件移动到名称以文件名前2个字符开头的文件夹中

Applescript-将文件移动到名称以文件名前2个字符开头的文件夹中,applescript,Applescript,我需要一些帮助来微调这个脚本。是否可以让此脚本根据文件的前两个字母匹配子文件夹?父文件夹将是“快照”,其中包含具有唯一两个字母前缀“BA_Bikini_Atol”的子文件夹,其中包含特定快照BA_0020、BA_0030等文件夹中的子文件夹。要通过选择“快照”将文件BA_0020_V002移动到BA_0020文件夹中目标和脚本在所有子文件夹中查找匹配项。想法 set mgFilesFolder to (choose folder with prompt "Where are the files

我需要一些帮助来微调这个脚本。是否可以让此脚本根据文件的前两个字母匹配子文件夹?父文件夹将是“快照”,其中包含具有唯一两个字母前缀“BA_Bikini_Atol”的子文件夹,其中包含特定快照BA_0020、BA_0030等文件夹中的子文件夹。要通过选择“快照”将文件BA_0020_V002移动到BA_0020文件夹中目标和脚本在所有子文件夹中查找匹配项。想法

set mgFilesFolder to (choose folder with prompt "Where are the files stored which you would like to move to the destination?")
set mgDestFolder to (choose folder with prompt "Where is the destination folder?")

tell application "System Events"
    set folderList to name of folders of mgDestFolder
    set fileList to name of files of mgFilesFolder
end tell

repeat with i from 1 to (count folderList)
    set folderName to item i of folderList
    set filesToMove to {}
    repeat with j from 1 to (count fileList)
        set filename to item j of fileList
        if filename begins with folderName then
            set end of filesToMove to alias ((mgFilesFolder as string) & filename)
        end if
    end repeat

    tell application "Finder"
        move filesToMove to alias ((mgDestFolder as string) & folderName & ":")
    end tell
end repeat
我(在本网站用户的帮助下)制作了您所指的脚本。
从那以后,我制作了类似的(更高效的)脚本。它们中的大多数依赖于ASObjC Runner,您可以在这里获得:

如果已安装,我认为以下脚本将起作用:

set mgFilesFolder to (choose folder with prompt "Where are the file stored which you would like to move?")

set mgDestFolder to (choose folder with prompt "Where are destination folders?")

tell application "ASObjC Runner"

set mgFiles to enumerate folder mgFilesFolder with recursion without including folders
repeat with mgFile in mgFiles
    set mgPrefix to text 1 thru 7 of name of (about file mgFile include only "name")
    set mgDest to enumerate folder mgDestFolder match prefix mgPrefix with recursion
    manage file mgFile moving into mgDest
end repeat
end tell
这在我的测试中有效

     set mgFilesFolder to (choose folder with prompt "Where are the files stored which you would like to move to the destination?")
        set mgDestFolder to (choose folder with prompt "Where is the destination folder?")


        (* get the files of the mgFilesFolder folder *)
    tell application "Finder" to set fileList to files of mgFilesFolder

    (* iterate over every file *)
    repeat with i from 1 to number of items in fileList
    set this_item to item i of fileList

    set this_file_Name to name of this_item as string

    (* get the file name code
    Using the delimiter "_"  break the name into fields of text and returning fields 1 thru 2 .   i.e ba_0030 *)
    set thisFileCode to (do shell script "echo " & quoted form of this_file_Name & " |cut -d  _ -f 1-2")
    log thisFileCode
    tell application "Finder"
        set folderList to ((folders of entire contents of mgDestFolder) whose name starts with thisFileCode)
        if folderList is not {} then

            move this_item to item 1 of folderList
        end if
    end tell
end repeat
发件人:

致:


不完全是重复的,但是这个问题显示了如何根据文件名的开头移动文件:Darrick-这是我正在使用的脚本,工作非常好,但是我如何让脚本查找子文件夹进行匹配?谢谢Sirbax。我的系统软件是OSX 10.9.1。我知道ASObjC Runner最多只支持10.9。有没有办法在没有ASObjC助手的情况下将此脚本保存在Apple脚本中?我认为它也将在10.9.1上运行。你试过了吗。该脚本只需要ASObjC提供的applescript命令Runner@Mull我已经对脚本进行了修改,并在10.9.1上进行了测试。它起作用了。如果要移动的文件与要将其移动到的子文件夹位于同一文件夹中,则必须删除mgfilesfolderThank的with递归位sirbaxx。但在接近的时候,出现了一个问题。我的源文件文件夹中有多个文件具有相同的前缀,即:ba_0020_v002、ba_0020_v003、ba_0020_v0023等。这是脚本中断的地方。如果我从源文件夹中删除所有的倍数,脚本就会工作。有什么想法?马克亨特。非常感谢。一个后续问题。如果我想在目标文件夹中为所有.mov文件添加一个名为“qts”的文件夹,该怎么办。你有什么想法吗?