Re: Finding and deleting specific extensions.
Re: Finding and deleting specific extensions.
- Subject: Re: Finding and deleting specific extensions.
- From: Christopher Nebel <email@hidden>
- Date: Sun, 14 Sep 2003 13:01:26 -0700
On Sep 14, 2003, at 4:31 AM, John Stewart wrote:
On 9/13/03 at -0700 Team Loco said this
I am trying to see if there is a way to have an apple script that
searches for a specific file extension (html) within a given folder
and moving it to the trash; possibly with a confirmation dialog.
I've found ways to display asking to pick a folder, but I am not
quite sure how to implement this, and I would like to eventually have
it as a folder action.
Here is a very simple OS X specific script that covers the basics. It
needs a few bells and whistles added such as checking for .htm files,
recursion for sub-folders and error checking.
Be careful of line wrapping.
(* script *)
set foldPath to choose folder with prompt "Pick your folder"
tell application "Finder"
set extension hidden of every file of foldPath to false -- OS X
specific
set fList to every file of foldPath whose name ends with ".html"
repeat with aFile in fList
move (contents of aFile) to trash
end repeat
set extension hidden of every file of foldPath to true -- if wanted
end tell
(* end script *)
Except that it doesn't have any of the mentioned bells and whistles,
and could be written much more simply:
1. Don't write loops in AppleScript if you don't have to -- it's slower
and less clear.
2. The Finder's "name" property is the name *with* the extension, so
the showing and hiding is unnecessary.
3. In Mac OS X, there is a "name extension" property you can use.
However, it amounts to the same thing as "name ends with".
Taking all that into account:
set f to choose folder with prompt "Pick your folder"
tell application "Finder"
move (every file of f whose name extension is "html") to trash
end tell
--Chris Nebel
AppleScript Engineering
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.