Reorganize a folder based on file names
Hello everyone,
i want to reorganize a folder with multiple subfolders, so that will look like:
MainFolder
__client1
____folderByName1
____folderByName2
____ecc.
__client2
____folderByName1
____folderByNamen
etc..
I wrote something that by now don't work and I don't understand why:
set main_folder to (choose folder with prompt "Choose the main folder")
tell application "Finder"
set client_folders to folders of main_folder
repeat with current_client_f in client_folders
set sub_folders to folders of current_client_f
tell application "Finder"
move every file of the every folder of folder sub_folders to alias current_client_f
end tell
set client_files to every file of current_client_f
repeat with actual_file in client_files
set actual_name to actual_file as string
set oldDelimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to "_"
set draw_folder to every text item of actual_name
set AppleScript's text item delimiters to oldDelimiters
set draw_folder_name to first item of draw_folder
try
make new folder in current_client_f with properties {name:draw_folder_name}
make new folder in current_client_f & draw_folder_name with properties {name:"DXF"}
make new folder in current_client_f & draw_folder_name with properties {name:"Bend"}
make new folder in current_client_f & draw_folder_name with properties {name:"Proj"}
end try
if (actual_file whose name extension is in {"pdf", "dwg"}) then
move to folder draw_folder_name of folder current_client_f with asking
end if
if (actual_file whose name extension is in {"dxf"}) then
move to folder "DXF" of folder draw_folder_name of folder current_client_f with asking
end if
if (actual_file whose name extension is in {"SLDPRT", "SLDASM", "SLDDRW", "step", "iges", "stp", "igs", "x_t"}) then
move to folder "Proj" of folder draw_folder_name of folder current_client_f with asking
end if
--move (every file of main_folder whose name extension is in {"dxf"}) to folder "DXF" of folder main_folder with replacing
--move (every file of main_folder whose name extension is in {"SLDPRT", "SLDASM", "SLDDRW", "step", "iges", "stp", "igs", "x_t"}) to folder "Proj" of folder main_folder with replacing
end repeat
end repeat
end tell
Any help would be appreciated.
Later I eventually even parse some folder files because the word that have to make a directory name it's inside the file name not at the start not at the end,
something like: asdfG56gtfr.pdf where the folder that should be created it's G56 so my intention is to make a list and parse file names of specified client folder to match product family and make folder by that then move file into it.
Hope it's enough clear, my English it's not the best I know that :P
Thanks.
MacBook Pro 16″, macOS 11.1