Re: RegExps in AS
Re: RegExps in AS
- Subject: Re: RegExps in AS
- From: kai <email@hidden>
- Date: Thu, 24 Feb 2005 03:07:47 +0000
On Wed, 23 Feb 2005 09:41:03 -0500, John Stewart <email@hidden>
wrote:
On 2/22/05 at 11:34 PM, the entity kai spoke thusly
On Monday, February 21, 2005, at 10:25 pm, Ihar 'Philips' Filipau
wrote:
On 20 Feb 2005, at 22:02, kai wrote:
One way might be to use AppleScript's text item delimiters:
Or one could do it with nothing but the Finder which doesn't need
RegEx or TIDs.
I agree:
http://lists.apple.com/archives/applescript-users/2005/Feb/msg00694.html
This isn't going to set any speed records but it is accurate. It's
also easily changed to filter extensions by adding a 'whose' clause.
--> Cut <--
tell application "Finder"
set flist to every file of (choose folder) as alias list
repeat with aFile in flist
set temp to contents of aFile
set oldExt to extension hidden of temp
set extension hidden of temp to true
set fname to displayed name of temp
set extension hidden of temp to false
set name of temp to fname
set extension hidden of temp to oldExt
end repeat
end tell
--> Cut <--
That appears to return a Boolean value, rather than a list of names.
More importantly, I'm afraid that I have to advise folks not to try
running this script as it stands - since it will permanently strip
extensions from *all* files in a folder (even those with previously
hidden extensions). Test it on a folder containing numerous files with
various extensions, and you could end up with quite a bit of repair
work on your hands. (The offending line: 'set name of temp to fname'.)
Also, don't forget that if you're going to use the Finder's 'as alias
list' command, you'll need to trap it for the possibility of a folder
that contains only one item.
The following suggestion aims to sidestep these potential problems and
to restore individual extensions - but without resorting to a repeat
loop (making it significantly faster):
-------------------------
tell application "Finder" to tell folder (choose folder)
tell (files whose extension hidden is false)
set n to name
set extension hidden to true
end tell
set l to displayed name of files
set extension hidden of files whose name is in n to false
end tell
l
-------------------------
---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden