2014-02-20 93 views
0

有人请让我开始使用Automator和/或AppleScript。我对此感到有点沮丧。我想按照预定顺序(可能是按名称或按日期)取一个非常大的文件夹(数千个),并将它们移动到子文件夹中,每个文件夹的大小不超过指定大小(可能为4.7GB)。我不希望ISO或DMG或任何只是我的文件很好地分割成磁盘大小的块。没有重新洗牌的命令。如果一个磁盘只适合一个10MB的文件,因为下一个文件会打破极限,那就这样吧。如果你想知道的话,没有任何文件会超过限制 - 它们将高达50MB左右。将文件拆分为文件夹

到目前为止,我已经得到了与获取所选Finder项目,随后该AppleScript的

on run {input, parameters} 
    return first item of input 
end run 

这让我的第一个项目文件夹操作。我可以创建一个文件夹磁盘1也是。我也可以移动文件。但是,我该如何解决是否要移动到此文件夹,或者是否需要创建新文件夹?

我想在Automator中这样做,如果可能的话,但怀疑我需要一点AppleScript。我相信这个问题已经解决了,所以如果可以的话请联系我。谢谢。

+0

是不够公平。但是我现在已经有了一个盘子,希望有人能够花上几分钟的时间,给我一些我可以继续使用的东西。 – MJM

+0

我是一个Windows人。 Macs不是我的特长。我不好。 – MJM

+2

当你说Actionscript时,你的意思是Actionscript,还是你的意思是Applescript?另外,也许命令行/终端是要走的路。 –

回答

0

继承人一个正在工作的AppleScript将这样做。这是不完美的,但完成工作。

它可以很慢的文件很多,我敢肯定它可以改善。高性能不是Applescript的强项之一。

tell application "Finder" 
    set files_folder to folder POSIX file "/Users/MonkeyMan/Desktop/MyMessOfFiles" 
    set destination_folder to folder POSIX file "/Users/MonkeyMan/Desktop/SortedFiles" 

    set target_size to 250.0 -- size limit your after in MB. 

    set file_groupings to {} -- list we will store our stuff in 
    set current_files to {} -- list of the current files we are adding size 

    set total_files to the count of files in files_folder 

    set current_size_count to 0 

    repeat with i from 1 to total_files 
     set file_size to (the size of file i of files_folder)/1024.0/1024.0 -- convert to MB to help prevent overrunning what the variable can hold 

     if ((current_size_count + file_size) ≥ target_size) then 
      -- this will overrun our size limit so store the current_files and reset the counters 
      set the end of file_groupings to current_files 
      set current_files to {} 
      set current_size_count to 0 
     end if 

     set current_size_count to current_size_count + file_size 
     set the end of current_files to (a reference to (file i of files_folder) as alias) 

     if (i = total_files) then 
      -- its the last file so add the current files disreagarding current size 
      copy current_files to the end of file_groupings 
     end if 

    end repeat 

    -- Copy the files into sub folders 
    set total_groups to the count of file_groupings 
    repeat with i from 1 to total_groups 
     set current_group to item i of file_groupings 
     set dest_folder to my ensureFolderExists(("disk " & i), destination_folder) 
     move current_group to dest_folder 
    end repeat 

end tell 

say "finished" 

on ensureFolderExists(fold_name, host_folder) 
    tell application "Finder" 
     if not (exists folder fold_name of host_folder) then 
      return make new folder at host_folder with properties {name:fold_name} 
     else 
      return folder fold_name of host_folder 
     end if 
    end tell 
end ensureFolderExists