Re: text item delimiters maddness
Re: text item delimiters maddness
- Subject: Re: text item delimiters maddness
- From: Kai <email@hidden>
- Date: Wed, 05 Feb 2003 09:37:03 +0000
on Mon, 3 Feb 2003 13:59:59 -0500, James Burns
<email@hidden> wrote:
>
Today I have a question about how to properly extract select chunks
>
from a path, to truncate it to a certain length. Here's what I was
>
using:
>
>
set fileContents to read file sceneFile -- read chosen file
>
set text item delimiters to ":"
>
set conDir to ((words 1 thru -3 of sceneFile) as string) & ":" --
>
figure out content directory
>
>
... and this works fine for most files, except those that have the
>
underscore character in them.
>
>
Thus, a path of:
>
>
"TiBook1:Documents:jpb Projects:News24 Houston:scenes:News24in_02.lws"
>
>
becomes:
>
>
"TiBook1:Documents:jpb:Projects:News24:Houston:scenes:News24in:_:"
>
>
Any clever thoughts out there? Thanks in advance...
Not as mad as it might appear, James.
Since certain characters ("+", "&", "_", etc.) are regarded as words, they
will add extra items to your word list:
----------------------------------
words of "News24in02.lws"
--> {"News24in02", "lws"}
words of "News24_in02.lws"
--> {"News24", "_", "in02", "lws"}
----------------------------------
To avoid _all_ potential problems using 'words', any routine that checked
for the presence of such characters would need to consider every
possibility.
But it doesn't end there. Notice above how the use of 'words' changes the
rest of your path from:
----------------------------------
"TiBook1:Documents:jpb Projects:News24 Houston:" etc...
----------------------------------
to:
----------------------------------
"TiBook1:Documents:jpb:Projects:News24:Houston:" etc...
----------------------------------
So - best not use 'words' at all in this situation.
As Michelle pointed out, you should really use 'text items'. When using ":"
as your text item delimiters, this would list a string like "News24in02.lws"
as a single item - as well as preserve the integrity of other items in your
path:
----------------------------------
--> {"TiBook1", "Documents", "jpb Projects", "News24 Houston", "scenes",
"News24in_02.lws"}
----------------------------------
To truncate the path to the parent folder, all you need now is something
like this:
==========================================
set {tid, text item delimiters} to {text item delimiters, ":"}
set conDir to (sceneFile's text items 1 thru -2 as string) & ":"
set text item delimiters to tid
==========================================
Alternatively, you could use the Finder, like this:
==========================================
tell application "Finder" to set conDir to file sceneFile's folder as string
==========================================
--
Kai
_______________________________________________
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.