• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [Q] How to get a containing folder of a given file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Prev by Date: [LIST MOM] WAS: Re: [Q] How to get a containing folder of a given file?
  • Next by Date: Re: [LIST MOM] WAS: Re: [Q] How to get a containing folder of a given file?
  • Previous by thread: Re: [LIST MOM] WAS:
  • Next by thread: Re: [Q] How to get a containing folder of a given file?
  • Index(es):
    • Date
    • Thread