Tomé prestado el código de abajo de este hilo: ¿Cómo clasificar archivos con nombres similares en carpetas distintas? (AppleScript)
Pero me gustaría dar un paso más para situaciones como ésta:
DE:
- VD010234.mp4
- VD010235.mp4
- VD020234.mp4
- VD020235.mp4
- VD030234.mp4
- VD030235.mp4
A:
01234 (Carpeta)
- VD010234.mp4
- VD020234.mp4
- VD030234.mp4
01235 (Carpeta)
- VD010235.mp4
- VD020235.mp4
- VD030235.mp4
En esencia, sólo mirar una parte del nombre del archivo, en el caso anterior, 234 y 235, y encontrar todos los archivos con esa referencia y ponerlos en carpetas tituladas.
set DELIM to {".mp4", ".", ":"}
tell application "Finder"
-- assumption: selection is a Finder selected containing folder of the items
set selected to selection
set current_folder to (first item of selected) as text as alias
set mlist to (sort (every item of folder current_folder) by name) as alias list
set {TID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, DELIM}
if mlist is {} then return
repeat with this_file in mlist
-- the DELIM guarantees that this item is the basename without extension
set basename to text item -2 of (this_file as text)
-- avoids duplicate folder name collisions
if not (exists folder ((current_folder as text) & basename)) is true then
set new_folder to make new folder at current_folder with properties {name:basename}
end if
move (this_file as text) to new_folder
end repeat
set AppleScript's text item delimiters to TID
end tell