Re: Parent path. Senility?
Re: Parent path. Senility?
- Subject: Re: Parent path. Senility?
- From: Jason Bourque <email@hidden>
- Date: Sat, 02 Dec 2000 19:22:37 -0500
>
I must be getting senile, for I can't for the life of me get the
>
colons back in without a repeat loop. Emmm, a little help please?
>
>
on open (f)
>
set {oldTID, AppleScript's text item delimiters} to {AppleScript's text item
>
delimiters, ":"}
>
if (f as string)'s last text item is "" then --its a folder
>
set ItmsparentPath to text items 1 thru -3 of (f as string)
>
-->{"disk", "folder"}
>
else
>
set ItmsparentPath to text items 1 thru -2 of (f as string)
>
-->{"disk", "folder"}
>
end if
>
set AppleScript's text item delimiters to oldTID
>
end open
>
>
PS I know this will break if a disk is dropped. I'll fix that later.
Below are two handlers I use I like the first it doesn't use text item
delimiters and retunrs the name of the path and It's parent folder without
the use of the finder. The second can get any level of the path you want.
Jason Bourque
--set thisFolder to "Macintosh HD:Desktop Folder:Master Server Apps:Common
Handlers"
--fileNameParentFolder(thisFolder)
--return result
on fileNameParentFolder(filePath)
if filePath ends with ":" then
set filePath to text 1 thru -2 of filePath
end if
--Name of item
set nameFound to (reverse of (items 1 thru ((offset of ":" in (reverse
of (every item of filePath) as string) as string) - 1) ,
of (reverse of (every item of filePath) as string))) as string
--parent folder of item
set ParentFolder to ((reverse of (items (offset of ":" in (reverse of
(every item of filePath) as string) as string) thru -1) ,
of (reverse of (every item of filePath) as string))) as string
--return record for use
return {nameFound, ParentFolder}
end fileNameParentFolder
--ParentFolder(x, 1)
--return result --returns-->"Macintosh HD:Internet:Internet Applications:"
--Note: if their are more levelsUp than levels to go up or if levelsUP = 0
then the disk is returned.
on ParentFolder(aFilePath, levelsUp)
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
if (count of text items of aFilePath) < (levelsUp + 1) or levelsUp = 0
then
set levelsUp to (count of text items of aFilePath) - 1
end if
set desiredPath to (text items 1 thru -(levelsUp + 1) of aFilePath as
string) & ":"
set AppleScript's text item delimiters to tid
return desiredPath
end ParentFolder