Ok a issue I have found may be you awesome experts can help me with.

Ok a issue I have found may be you awesome experts can help me!

This code deletes all the files in a folder: “ALL of them”

set folderOne to “testQ”

tell application “Finder”
delete (files of folder (“Macintosh HD:Users:JackDamore:Downloads:” & folderOne))
end tell

This codes deletes all the files except Keynotes and RTF files also I have not tried all other types yet?

So what is that happing? I’m baffled by this!

tell application “System Events”

set currentUser to (name of current user)

end tell

set userHome to path to home folder as text

set folderOne to “testQ”

tell application “System Events”
delete (files of folder (userHome & “Downloads:” & folderOne))

end tell

say currentUser

say userHome

Help Please! BigJack!

I’m not sure what is the question here, but one thing for sure

tell application "Finder"

is the one that should be used to delete files. At least Finder is always the app I’ve used in the past. I know System Events has two delete commands and this is probably where you’re having a problem in your second script. You need to specify a disk object (alias) most certainly so it is not confused.

But I’d stick with Finder nonetheless…

Browser: Safari 537.78.2
Operating System: Mac OS X (10.8)

That was it thanks!

My advice is the exact opposite :

Don’t speak to the Finder as long as it’s not absolutely required.
Finder is an old beast which doesn’t evolve seriously with the operating system.
Just an example : Standard Additions and System Events are aware of the property type identifier which is the modern way to identify a type of disk items. The declining Finder don’t know this property.

When we want to delete a single disk item whose pathname is known, System Events does the job correctly.
Here, the problem is that it fails to delete every items of a folder in a single call.
As we saw in an other thread open by BigJack,
delete files of folder myBeautifulFolder
behaves flawlessly to delete flatfiles.
What is puzzling is that it seems that this kind of syntax doesn’t apply to packages or folders which, like flatfiles are disk items.
Given this odd behaviour, if we want to use System Events, we must delete the disk items one by one with :

set userHome to path to home folder as text
-->> "<startup Volume>:Users:<current User>:"
set folderOne to "testQ"
tell application "System Events"
   set theItems to every disk item of folder (userHome & "Downloads:" & folderOne) # EDITED
   repeat with anItem in theItems
       delete disk item (path of anItem)
   end repeat
end tell

I continue to think that if we want to really delete items, triggering System Events is better because the Finder just move them to the trash were they remain as long as we don’t empty it.

Yvan KOENIG (VALLAURIS, France) jeudi 25 septembre 2014 15:25:58