Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

Posted on Jan 6, 2021 1:53 AM

Reply
Question marked as Best reply

Posted on Jan 6, 2021 12:07 PM

In the move line, you are passing a list of folders to the folder preposition. You need to single folder reference.

You could try

repeat with aFolder in {<your list of folders>}
move every file of every folder in aFolder to folder …
end repeat


Similar questions

5 replies

Jan 6, 2021 9:48 AM in response to Barney-15E

No it never worked, I just started writing and now I don't know where is the problem...

that's the result/error running the script:

tell application "Script Editor"
	choose folder with prompt "Choose the main folder"
end tell
tell application "Finder"
	get every folder of alias "Macintosh HD:Users:paolo:Desktop:Archivio copia:"
	get every folder of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk
	move every file of every folder of folder {folder "19B" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "20A" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "20B" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "21A" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "22B" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "22a" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk} to alias (folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk)
Risultato:
error "Finder ha trovato un errore: Non posso trasformare {folder \"19B\" of folder \"client01\" of folder \"Archivio copia\" of folder \"Desktop\" of folder \"paolo\" of folder \"Users\" of startup disk, folder \"20A\" of folder \"client01\" of folder \"Archivio copia\" of folder \"Desktop\" of folder \"paolo\" of folder \"Users\" of startup disk, folder \"20B\" of folder \"client01\" of folder \"Archivio copia\" of folder \"Desktop\" of folder \"paolo\" of folder \"Users\" of startup disk, folder \"21A\" of folder \"client01\" of folder \"Archivio copia\" of folder \"Desktop\" of folder \"paolo\" of folder \"Users\" of startup disk, folder \"22B\" of folder \"client01\" of folder \"Archivio copia\" of folder \"Desktop\" of folder \"paolo\" of folder \"Users\" of startup disk, folder \"22a\" of folder \"client01\" of folder \"Archivio copia\" of folder \"Desktop\" of folder \"paolo\" of folder \"Users\" of startup disk} nel tipo integer." number -1700 from {folder "19B" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "20A" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "20B" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "21A" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "22B" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk, folder "22a" of folder "client01" of folder "Archivio copia" of folder "Desktop" of folder "paolo" of folder "Users" of startup disk} to integer


the error in English should be "can't convert folder...... ...to integer



thanks

Reorganize a folder based on file names

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.