Need Help Scripting File Deletion

I am trying to write an applescript that will allow me to delete multiple files on a computer, and then do a secure empty trash.

My problem is that lets say one of the specified files is not on the computer, how do I have the Applescript still proceed with the rest of the applescript.

This applescript is needed for deletion of old programs on school computers. Some computers have all of the programs and others do not.

Currently all that happens if this will delete files until applescript gets to a program not on the system, and then if stops the program to tell me of the non existent application.

Instead I would like the applescript to:

  1. delete all of the specified files it can find on the computer

  2. secure empty the trash

  3. prompt me with an error dialog box that details what applications were not found on the system

Any help would be greatly appreciated.

Regards,
paulmattallen

do shell script "command" user name "Your Computer" password "passcode" with administrator privileges

try
	
	set theFile to "/Users/bradleyelementary/Desktop/santas 2.qtz"
	do shell script "rm -R " & quoted form of theFile & "" with administrator privileges
	
	
	do shell script "/usr/bin/srm -mz $HOME/.Trash/*" with administrator privileges
	
on error
	display dialog "The following applications were not found on this system..." with icon caution with title "Error" giving up after 5
	
end try

Hi,

Removing the on error part from the try block might already do the job (plus some enhancements):


on run
	set itempaths to {"/Users/martin/Desktop/photoshopcs.jpg", "/Users/martin/Desktop/cups-pdf/job_29-dumpix_m.pdf", "/Users/martin/Desktop/cups-pdf", "/Users/martin/Desktop/b0649af7-963c-2e6e-b212f1af4ea36683.jpg"}
	
	set report to ""
	repeat with itempath in itempaths
		if not my itempathexists(itempath) then
			set entry to "Could not locate item '" & itempath & "'" & return
			set report to report & entry
		else
			try
				set command to "rm -rf " & quoted form of itempath
				do shell script command
			on error errmsg
				set entry to "Deleting the following item failed:" & return & tab & itempath & return & errmsg & return
				set report to report & entry
			end try
		end if
	end repeat
	
	if report is not "" then
		tell application "TextEdit"
			activate
			if not (exists document 1) then
				make new document
			end if
			set text of document 1 to report
		end tell
	end if
end run

on itempathexists(itempath)
	try
		set itemalias to (POSIX file itempath) as alias
		return true
	on error
		return false
	end try
end itempathexists