AppleScript: Move contents of folder in user defined amount to folders? -
i'm new @ , while having managed created several basic scripts on last few weeks cannot seem wrap head around one:
- choose folder (with 1000 files)
- enter number of files per folder (say 100)
- the script creates 10 folders (1000 files / 100 in each folder)
- the script moves first 100 files sequentially the first folder - repeats till done.
the scripts i've put process point dismal, sloppy , outright pathetic dare not share them here.
my experiments have resulted in item listing causing issues moving files sequentially. instead of: valone_1.wav valone_2.wav valone_3.wav valone_4.wav valone_5.wav
i get: valone_1.wav valone_10.wav valone_100.wav valone_101.wav valone_102.wav
thanks
the finder has "sort" command can use avoid numbering problem mention. seems sort them way expect. using workflow becomes easy little clever coding. try following. need adjust first 2 variables in script suit needs , rest of script should work.
set filesperfolder 3 set newfolderbasename "storagefolder_" set chosenfolder (choose folder) text tell application "finder" -- files chosen folder , sort them set thefiles files of folder chosenfolder set sortedfileslist sort thefiles name set thecounter 1 repeat -- calculate list of files move -- remove files sortedfileslist if (count of sortedfileslist) greater filesperfolder set movelist items 1 thru filesperfolder of sortedfileslist set sortedfileslist items (filesperfolder + 1) thru end of sortedfileslist else set movelist sortedfileslist set sortedfileslist {} end if -- calculate new folder information , make set newfoldername newfolderbasename & thecounter text set newfolderpath chosenfolder & newfoldername if not (exists folder newfolderpath) make new folder @ folder chosenfolder properties {name:newfoldername} end if -- move movelist files move movelist folder newfolderpath if sortedfileslist {} exit repeat set thecounter thecounter + 1 end repeat end tell
Comments
Post a Comment