Find specific folder on all local disks and delete them

I’m trying to make a script that will search for a folder named “deleteme” on all local disks (and it will likely exist on all local disks) and delete any folders it finds (as well as the contents). I can’t figure out how to get the paths for deleting them though. As always, help is SO MUCH appreciated. Thanks. :slight_smile:

-Evan

Hi Evan,

scanning the entire contents of every disk takes a real real real long time.
Can you specify the paths a bit more?

Actually yes, it would be a folder of name “deleteme” at the root level of each local drive that I want to delete. Thanks for any advice. :slight_smile:

this will be much faster :wink:

You can do it with this code:

tell application "Finder"
	set allDisks to disks whose name is not "Network"
	repeat with theDisk in allDisks
		delete (every folder of theDisk whose name is "deleteme")
	end repeat
end tell

hi All,

I am trying to do a similar thing to this

There is a folder on my desktop called “Main folder” within this folder will be hundreds of job folders and within those folders are folders with different names like “artwork” “PDF” “PrintFiles” etc.

I am trying to delete the folder named “Printfiles” out of each of those folders everytime I run a script but I cant work out why it isnt working. Any help would really be appreciated.

Here is the script:


tell application "Finder"
	set Source_folder to "MacintoshHD:Users:Me:Desktop:Main folder:"
	
	repeat with delete_Me in Source_folder
	
	try
		move (every folder of delete_Me whose name is "PrintFiles") to trash
	end try
end repeat
end tell


Hi,

you forgot to retrieve the folders in Source_folder


tell application "Finder"
	set Source_folder to folder "Main folder:" -- the desktop folder is the "root" folder of the Finder
	
	repeat with delete_Me in (get every folder of Source_folder)
		try
			move (every folder of delete_Me whose name is "PrintFiles") to trash
		end try
	end repeat
end tell


Hi StefanK,

Thanks is much for your help, and the quick reply!

I am still new to scripting but am trying to learn, I can see where I went wrong now, I also worked out I could have defined the folders in a previous line like this:



tell application "Finder"
	set Source_folder to folder "Main folder:" -- the desktop folder is the "root" folder of the Finder
	set next_folder_Level to every folder of Source_folder
	repeat with delete_Me in next_folder_Level
		try
			move (every folder of delete_Me whose name is "PrintFiles") to trash
		end try
	end repeat
end tell


But your method is tidier than mine, so thanks I will use it.