Re: [Q] How to get a containing folder of a given file?
Re: [Q] How to get a containing folder of a given file?
- Subject: Re: [Q] How to get a containing folder of a given file?
- From: "Laine Lee" <email@hidden>
- Date: Wed, 20 Sep 2006 10:52:32 -0500
Here's a droplet source that I sometimes have fun with when I get angry at Finder.
on open (file_system_object)
set the_item_path to (file_system_object as Unicode text)
set myinfo to (info for file_system_object)
if folder of myinfo then
display dialog extract_parent_from_folder(the_item_path)
else
display dialog extract_parent_from(the_item_path)
end if
end open
--parent path of folder
on extract_parent_from_folder(this_folderpath)
set _target to this_folderpath
set postarget to (text items 1 thru -2 of (POSIX path of _target))
try
set containercommand to "expr /" & (quoted form of (postarget as Unicode text)) & space & ":" & space & " '/\\(.*\\)/'"
set parent_path to POSIX file (do shell script containercommand)
on error
set parent_path to (path to startup disk as Unicode text)
end try
return parent_path
end extract_parent_from_folder
--Parent path of file
on extract_parent_from(this_filepath)
set _target to this_filepath as Unicode text
set postarget to (POSIX path of _target)
try
set containercommand to "expr /" & (quoted form of postarget) & space & ":" & space & " '/\\(.*\\)/'"
set parent_path to (POSIX file (do shell script containercommand) as Unicode text)
on error
set parent_path to (path to startup disk as Unicode text)
end try
return parent_path
end extract_parent_from
--
Laine Lee
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden