Deleting a file in a folder

Hi,

I am developing a script which deletes all files that is contained in a specific folder.
This script works fine. But the problem occurs when any one file is currently opened.

If a file is opened during this script execution, it shows the message “The operation cannot be completed because the item “xxx.pdf” is in use.”

What I want is when a file is opened during the script execution, the script should ignore this file and deletes all other file.

My script is below:


property del : "folder1:TRASH:Gopal" as alias
tell application "Finder"
	try
		delete every file of folder del
		delete every folder of folder del
	on error
		display dialog "Could not delete the file"
	end try
end tell

Could any one help me on this.

Thanks,
Gopal

Hi Gopal,

My suggestion is to do it as follows:


property del : "folder1:TRASH:Gopal" as alias
tell application "Finder"
	set folderitems to every item in del
	repeat with folderitem in folderitems
		try
			delete folderitem
		end try
	end repeat
end tell