PathInfo Reference

PathInfo is an AppleScript library which provides object oriented interface to deal with file references.

In AppleScript various kind of file references are used i.e. alias, File URL, HFS path and POSIX path. PathInfo allow to unified way to convert each others and to obtain various infomation from file references.

Examples

use PathInfo : script "PathInfo"

set a_path to "/System/Library/CoreServices/Finder.app/"

(*** Class methods ***)
log PathInfo's name_of(a_path)
(*Finder.app*)
log PathInfo's basename_of(a_path)
(*Finder*)
log PathInfo's path_extension_of(a_path)
(*app*)
log PathInfo's split_name("basename.txt")
(*basename, txt*)
log PathInfo's folder_of(a_path)
(*/System/Library/CoreServices/*)

(*** Obtain path infomation ***)
set a_pathinfo to PathInfo's make_with(a_path)
log a_pathinfo's item_name()
(*Finder.app*)
log a_pathinfo's basename()
(*Finder*)
log a_pathinfo's path_extension()
(*app*)
log a_pathinfo's is_folder()
(*true*)
log a_pathinfo's item_exists()
(*true*)
log a_pathinfo's is_posix()
(*true*)

(*** Converting reference form ***)
log a_pathinfo's as_alias()
(*alias Macintosh HD:System:Library:CoreServices:Finder.app:*)
log a_pathinfo's as_furl()
(*file Macintosh HD:System:Library:CoreServices:Finder.app:*)
log a_pathinfo's posix_path()
(*/System/Library/CoreServices/Finder.app/*)
log a_pathinfo's hfs_path()
(*Macintosh HD:System:Library:CoreServices:Finder.app:*)

(*** Making a new instance from the instance ***)
log a_pathinfo's parent_folder()'s posix_path()
(*/System/Library/CoreServices/*)
log a_pathinfo's change_name("new_item")'s posix_path()
(*/System/Library/CoreServices/new_item/*)
log a_pathinfo's change_path_extension("txt")'s posix_path()
(*/System/Library/CoreServices/Finder.txt/*)
log a_pathinfo's change_folder("/aaa/bbb/")'s posix_path()
(*/aaa/bbb/Finder.app/*)
log a_pathinfo's child("child_item")'s posix_path()
(*/System/Library/CoreServices/Finder.app/child_item*)

Class methods

Obtain information from a path quickly.

name_of

Obtain a name from a reference to a file/folder.

basename_of

Obtain a name of the item with removing a path extension.Almost types of references to a file or a folder can be accepted. e.g.) HFS path, POSIX path, alias, file specification, reference form of Finder and furl.

path_extension_of

Obtain a path extension of the item. The result does not starts with ".".

split_name

Split a file name into a base name and a path extension.

folder_of

Obtain a folder path

Constructor Methods

make_with

Make a PathInfo instance for a file reference.

make_with_hfs

Make a PathInfo instance for a file reference.

make_with_posix

Make a PathInfo instance for a file reference. A synonym of make_with

Obtain path information

item_name

Obtain a name of the file or the folder.

basename

Obtain a name without path extension.

path_extension

Obtain a path extension of the file name. The result does not starts with ".".

volume_name

Obtain the volume name of the item referenced by the instance.

folder_ref

Obtain a file reference to the folder containing the target.

is_folder

Whether the target is a folder or not.

item_ref

Obtain an internal file reference which the target contains.

item_exists

Whether an item exits in the file sysem or not.

item_exists_without_update

Whether an item exits in the file sysem or not.

is_posix

If child and change_folder prefer posix path, true is returned.

Converting reference form

as_alias

Obtain a file reference as alias.

as_furl

Obtain a file reference as File URL.

posix_path

Obtain a file reference as POSIX path form.

normalized_posix_path

Obtain POSIX path which does not end with "/".

hfs_path

Obtain a file reference as HFS path form.

as_text

Obtain a path text.

Making a new instance from the instance

parent_folder

Obtain an instance of PathInfo referencing the folder containing the target.

change_name

Make a new PathInfo changing the item name.

change_path_extension

Make a new PathInfo changing the path extension.

change_folder

Make a new PathInfo changing the folder.

child

Make a new PathInfo appending a sub path.

clone

Make a new PathInfo which refering the same file to the target.

Error Numbers and Error Messages