Re: how do you tell what folder a file is in? - how to tell if a file exists part
Re: how do you tell what folder a file is in? - how to tell if a file exists part
- Subject: Re: how do you tell what folder a file is in? - how to tell if a file exists part
- From: JollyRoger <email@hidden>
- Date: Sun, 28 Oct 2001 07:02:45 -0600
On 10/26/2001 1:27 PM, "Arthur Cormack" <email@hidden> wrote:
>
on getParentFolder(whichOne) --which one is an alias to a file
>
set oldDelims to AppleScript's text item delimiters
>
set AppleScript's text item delimiters to {":"}
>
set thisOne to the text items of (whichOne as text)
>
set thisTextItemCount to count the (text items of thisOne)
>
set thisFullPathToFolder to ((text items 1 thru (thisTextItemCount -
>
1) of thisOne) as text) --& ":"
>
set AppleScript's text item delimiters to oldDelims
>
return thisFullPathToFolder
>
end getParentFolder
Hi Arthur,
The handler you posted doesn't work if you pass it a folder. Also, it
doesn't pass the entire path of the parent folder, only the name. :/
I've been using the following handler for ages. It does all of the above:
-- begin script
return ParentFromPath((path to the startup disk as text) & "Desktop
Folder:", true)
on ParentFromPath(thePath, wantPath)
set thePath to (thePath as text)
set saveDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to {":"}
set pathAsList to text items of thePath
if the last character of thePath is ":" then
set idx to (the number of text items in thePath) - 2
else
set idx to -2
end if
if wantPath then
set folderName to ((text items 1 through idx of pathAsList) as text)
& ":"
else
set folderName to item idx of pathAsList
end if
set AppleScript's text item delimiters to saveDelim
return folderName
end ParentFromPath
-- end script
HTH
JR