Re: Path-Strings to Formatted String
Re: Path-Strings to Formatted String
- Subject: Re: Path-Strings to Formatted String
- From: Jason Bourque <email@hidden>
- Date: Fri, 15 Feb 2002 23:31:21 -0500
Well, I just put this together, remember to insert your favorite sort
routine.
Let me know if you want files included, I don't know if it works with them.
Thanks,
Jason Bourque
set vIndent to tab
set vFolderList to {"MacHD:Projects:Project 1:Art:CHAP01:", ,
"MacHD:Projects:Project 1:Art:CHAP02:", ,
"MacHD:Projects:Project 2:Art:CHAP01:", ,
"MacHD:Projects:Project 2:Art:CHAP02:", ,
"MacHD:Projects:Project 2:Old:CHAP01:", ,
"MacHD:Projects:Project 2:Old:CHAP01:Page 1:", ,
"MacHD:Projects:Project 2:Old:CHAP02:", ,
"MacHD2:Projects:Project 2:Old:CHAP01:"}
--Sort the list
tell me to SortaList(vFolderList)
set vFolderList to result
-- Capture the delimiters
set vTids to AppleScript's text item delimiters
-- Temp variables
set vHeirarchyList to {}
set vIndentList to {}
set vMaxMatch to {}
repeat with vNth from 1 to count of vFolderList
set AppleScript's text item delimiters to ":"
set vItemNth to text items of item vNth of vFolderList
repeat with vNth2 from 1 to ((count of vItemNth) - 1)
set vItemNth2 to item vNth2 of vItemNth
try
set vMaxMatchItem to item vNth2 of vMaxMatch
on error
set vMaxMatchItem to ""
end try
if vItemNth2 is not vMaxMatchItem then
set AppleScript's text item delimiters to ""
-- Build the indention
repeat (vNth2 - 1) times
set vIndentList to vIndentList & vIndent
end repeat
-- Capture the folder
copy ((vIndentList as text) & vItemNth2) to end of
vHeirarchyList
-- Reset the indention
set vIndentList to {}
-- Reset the match
set vMaxMatch to {}
end if
end repeat
copy text items 1 thru -3 of vItemNth to vMaxMatch
end repeat
-- Separate the lines of text with a paragraph return
set AppleScript's text item delimiters to ":" & return
-- Collapse the list as a string.
set vHeirarchyTxt to vHeirarchyList as text
-- Reset the delimiters
set AppleScript's text item delimiters to vTids
-- Variable CheckPoint
return vHeirarchyTxt
On 2/15/02 8:26 PM, "Arthur J Knapp" <email@hidden> wrote:
>
> Arthur,
>
>
>
> I wrote this a while ago, and I don't remember if I sorted the folders but
>
> it should do what you need.
>
>
Thank you Jason, I appreciate your response, but I'm afraid that this
>
was not what I was looking for.
>
>
> Save it as a droplet and drop a folder onto it.
>
>
Yeah, I really didn't explain the problem very well. I wasn't looking
>
for a folder-traversal script. In fact, I have written several such
>
scripts myself.
>
>
>
> on open theseItems
>
[snip]
>
> tell application "Finder"
>
>
The first problem is that my data is a list of path-strings, not
>
actual folder aliases or Finder objects. Secondly, in many cases,
>
my script needs to parse such information even when it was
>
generated on another computer, ie: the path-strings may not even
>
represent folders on the computer that my script is running on.
>
>
Because of this, the Finder cannot really assist in the problem.
>
>
[snip]
>
> set thisItem to (item i of theseItems)
>
> set the itemInfo to info for thisItem
>
> if folder of the itemInfo is true then
>
>
Right, find out if a given item is a folder, then recurse appropriately.
>
>
The problem in my situation is that there is no fast way to know if
>
one folder "belongs" to another, ie: each path-string has it's entire
>
path in front of it, requiring one to parse out where in the heirarchy
>
it belongs, as opposed to recursing from one folder to another, where
>
you know that every item found at one level "belongs" at that level.
>
>
>
> on ASCIISort(myList)
>
>
Somewhat off of the topic: Why did the AppleScript team call this
>
"ASCII" sort? It is a serious misnomer.
>
>
>
>
To state the problem more succinctly, given *exactly* this type of data:
>
>
{ "MacHD:Projects:Project 1:Art:CHAP01:",
>
"MacHD:Projects:Project 1:Art:CHAP02:",
>
"MacHD:Projects:Project 2:Art:CHAP01:",
>
"MacHD:Projects:Project 2:Art:CHAP02:",
>
"MacHD:Projects:Project 2:Old:CHAP01:",
>
"MacHD:Projects:Project 2:Old:CHAP02:"
>
}
>
>
what is the best way for me to obtain this string:
>
>
"MacHD:
>
Projects:
>
Project 1:
>
Art:
>
CHAP01:
>
CHAP02:
>
Project 2:
>
Art:
>
CHAP01:
>
CHAP02:
>
Old:
>
CHAP01:
>
CHAP02:
>
"
>
>
where the indentations are tabs?
>
>
>
{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
>
<mailto:email@hidden>
>
try
>
<http://www3.sympatico.ca/victor.yee/>
>
on error number -128
>
end try
>
}
_______________________________________________
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.