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.
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
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
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
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.