Re: Getting file suffix
Re: Getting file suffix
- Subject: Re: Getting file suffix
- From: LuKreme <email@hidden>
- Date: Tue, 14 Sep 2010 08:03:10 -0600
On 13-Sep-2010, at 07:42, Mark J. Reed wrote:
>
> André told you how in the very next line of his message:
>
> tell app "Finder" to get the name extension of thisFile
Doh.
> But as Luther pointed out, the Finder is somewhat picky about what it
> considers a "name extension"; any old string of characters after a
> period doesn't quite cut it.
I'd actually assumed that the finder extension name would not work since the files I was testing by default were .nzb and .torrent, which I expected were rather non-standard extensions. However, Finder seems to return them just fine.
This is what I ended up with though, which I think will be safest in all cases:
on getSuffix(myFile)
tell application "Finder" to set myFile to name of myFile
if myFile contains "." then
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set theSuffix to last text item of myFile
set AppleScript's text item delimiters to oldDelims
return theSuffix
end if
end getSuffix
-- this_item is an alias in the after receiving list of the folder action
set item_suffix to getSuffix(this_item)
Which I think has the benefit that it's always going to work, regardless of if the finder gets the extension name or not.
> So to sum up: if your extensions are sufficiently Finder-friendly, you
> can just ask the Finder for them. If not, be sure to de-pathify the
> string first (split on colons or ask the Finder for an alias's "name")
> before looking for the period, and be sure to handle the case where
> there isn't one.
Thanks for everyone's comments.
--
Demons have existed on the Discworld for at least as long as the gods,
who in many ways they closely resemble. The difference is basically the
same as between terrorists and freedom fighters. --Eric
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden