Files and Folders (Directories)

The file system is an important part of any operating system, it’s where users keep their stuff. The organization of the file system plays an important role in helping the user find files. The organization also makes it easier for apps and the system itself to find and access the resources they need to support the user.

The file systems in Mac OS X and iOS are both based on the UNIX file system. All of the disks attached to the computer – whether they are physically plugged into the computer or are connected indirectly through the network – contribute space to create a single collection of files. Because the number of files can easily be many millions, the file system uses directories to create a hierarchical organization.

### File Paths

The location of any file or folder on disk is specified by a hierarchical path. All paths start with the / character, followed by a list of subfolders, with each subfolder separated by the / character. For example, the path

    /Users/tom/Documents/greatpicture.jpg

specifies that the file greatpicture.jpg is located in the folder Documents, which is located in the folder tom, which is located in the folder Users, which is located at the root level of the systems primary hard disk.

#### Secondary Disk Drives

If a file is not located on the primary hard disk, the path must begin with `/Volumes/<drive name>`. For example, the path

    /Volumes/Archives/Images/sunset.jpg

specifies that the file sunset.jpg is located in the folder Images on the hard drive named Archives.

#### Paths Relative to the Home Folder

If a path begins with the ~ character, the path is relative to the current user’s home folder. For example, the path

    ~/Pictures/waterfall.jpg

specifies that the file waterfall.jpg is contained in the Pictures folder inside the current user’s folder. If the current user is named sam, the path above is equivalent to:

    /Users/sam/Pictures/waterfall.jpg

#### Paths Relative to the Current Database

If a path doesn’t begin with the / or ~ characters, it is relative to the location of the current database. For example, the path

    mylogo.gif

specifies that the file mylogo.gif is in the same folder as the current database. The path

    artwork/signature.png

specifies that the file signature.png is located in the folder artwork, which is located in the same folder as the current database.

#### HFS Paths

For compatibility with older Panorama database, file paths can also be specified in HFS format. HFS stands for Hierarchical File System and is the format that was used in all versions of Mac OS prior to Mac OS X (Mac OS 9, 8, 7, etc.) HFS paths start with the drive name followed by a list of folders, all separated by colons. For example, the path:

    Archives:Images:sunset.jpg

specifies that the file sunset.jpg is located in the folder Images on the hard drive named Archives. Note: When using HFS format the drive name is always required, even for the primary disk (except for database relative paths, as described in the next section).

##### HFS Paths Relative to the Current Database

If an HFS path starts with the : character, the path is relative to the current database. For example, the path

    :artwork:signature.png

specifies that the file signature.png is located in the folder artwork, which is located in the same folder as the current database.

Note: If the first folder name is not the same as a drive name, the leading : can be omitted, like this:

    artwork:signature.png

However, if there is a drive named artwork mounted on the system, this will be treated as a regular, non-relative path.

##### Mixed Paths

Panorama allows you to mix different / and : characters in a path. If the path begins with a drive name followed by a colon, it is treated as an HFS path and / characters are interpreted as colons. Otherwise it is treated as a standard path and : characters are interpreted as slashes. Here are some examples:

    /Users/bob/Library/Preferences:AcmeSoft:Settings.plist
    Macintosh HD:Users/sam/Documents/letter.doc

### Folder IDs

In the HFS system that was used in all versions of Mac OS prior to Mac OS X (Mac OS 9, 8, 7, etc.), folders could be identified by Folder IDs, which were opaque 6 byte binary values that uniquely identified each folder. Previous versions of Panorama could convert a path into a Folder ID using the folder( function, and convert a Folder ID into a path with the folderpath( function, and also generated Folder IDs with functions like info(“panoramafolder”), dbfolder(, homesubfolder( and many others.

Unlike HFS, the Mac OS X file system (which is based on UNIX) does not use or support the concept of Folder IDs. All file locations are simply specified with paths, as described above. However, since so many Panorama functions and statements depend on Folder IDs, Panorama still supports their use. A path can be converted into a Folder ID with the folder( function. Folder IDs can also be created by functions that specify specific locations like info(“panoramafolder”), dbfolder(, homesubfolder( etc. A Folder ID can be converted into an HFS path with the folderpath( function.

Expert Tip: In previous versions of Panorama, since Folder IDs were opaque binary values, they could not be created manually, only with special functions. In the current version of Panorama, Folder IDs are no longer opaque binary values. Instead, they are simply standard, fully qualified paths. Fully qualified means that the path must be absolute (starting with /) and contain the complete path of the folder. Note: A Folder ID must not end with the / character.)

Here are some examples of valid Folder IDs:

    /Users/steve/Documents
    /Volumes/BigFatDisk/Programming/Perl
    /Users/mel/Movies/Baby

Here are examples of paths that are not valid Folder IDs:

    BigFatDisk:Programming:Ruby ☞ HFS is not allowed
    /Users/steve/Documents/  ☞ trailing / is not allowed
    artwork/logos  ☞ relative paths are not allowed

If you have any doubts, you can always use the folder( function to create the Folder ID for you. This function will convert any of the paths listed above into valid Folder ID paths. But if you format the path correctly, you can create a Folder ID with a simple assignment statement. The following two statements have the identical result:

    myfolder = folder("BigFatDisk:Programming:Perl")

will create a Folder ID using the folder( function (the standard path format could also be used).

    myfolder = "/Volumes/BigFatDisk/Programming/Perl"

will create a Folder ID directly.

Since a Folder ID is a valid path, you can use it anywhere a path is required, and you can manipulate Folder IDs using any of Panorama’s text tools. This program fragment checks to see if the Panorama application is installed in the Application folder.

    if info("panoramafolder") beginswith "/Application"
        do something
    endif

In previous versions of Panorama this wouldn’t have worked because the Folder ID did not contain text. Instead you would have had to convert to text using the folderpath( function, which of course will still work, but is significantly more complicated:

    if folderpath(info("panoramafolder")) beginswith firstline(info(volumes")+":Application"
        do something
    endif

See Also

- aliaspath( -- returns the path an alias points to (or an error if the specified file isn't an alias).
- archivecontents( -- lists the contents of a compressed archive in *.zip*, *.tar.gz* or *.tar.bz2* format.
- bookmarkpath( -- converts saved bookmark data (from the filebookmark( function) into a standard file path.
- bundleresourcepath( -- returns the file path and name of a specified item in the Panorama application bundle.
- choosefiledialog -- displays a modal dialog allowing selection of files or folders.
- choosefolderdialog -- pauses and displays the standard “choose folder” dialog.
- commonpath( -- returns the path for common folders (desktop, library, documents, pictures, etc.).
- compress -- compresses a file or an entire folder.
- copyfile -- copies a file (or folder).
- copyfolder -- copies an entire folder full of files (and subfolders, if any).
- copynewerfile -- copies a file to another name or location. However, the file is only copied if it is newer than the old file, otherwise the destination is not touched.
- copynewerfile( -- copies a file to another name or location. However, the file is only copied if it is newer than the old file, otherwise the destination is not touched.
- copynewerfolder -- copies an entire folder full of files, but only copies newer files.
- dbfolder( -- returns the folder path of the folder the current database is located in.
- dbname( -- returns the name of the current database.
- dbpath( -- returns the HFS path of the folder the current database is located in.
- dbsubfolder( -- returns the path of a subfolder within the same folder as the current database.
- dropfromfinder -- processes any files or folders that have been dropped on a form from the finder.
- dropimagesfromfinder -- processes images that have been dropped on a form from the Finder. The images may be added to new records in the database or put in the current record.
- enclosingfolder( -- takes a full path and filename and returns the name of the folder that contains the file.
- enclosingpath( -- takes a full path and filename and returns the path of the folder that contains the file.
- fileappend -- appends new data to an existing disk file.
- fileattributes( -- returns attributes of the specified file or folder (date, owner, permissions, etc.).
- filebookmark( -- converts a file or folder path into a binary data value that persistently links to the file, even if it is later moved or renamed.
- filecatalog( -- builds a text array listing the files in a folder, including any subfolders of that folder.
- filedate( -- returns the modification date of a file.
- filedisplayname( -- returns the display name for the specified file or folder.
- fileerase -- erases a disk file or a folder, removing it from the hard disk.
- fileexists( -- returns true if a file exists, false if it does not.
- fileexistspath( -- tests to see if a file exists.
- fileextension( -- extracts the extension (if any) from a partial or complete path and filename.
- filefolder( -- returns the folder ID of the folder that contains the specified file.
- fileidnumber( -- returns the id number for the specified file or folder.
- fileinfo( -- returns information about a file (or folder) on the disk, including the size, creation and modification date and time, type, creator and lock status.
- fileload( -- reads the entire contents of any file on disk.
- fileloadpartial( -- reads a portion of the contents of any file on disk.
- filename( -- extracts the filename from a complete path and filename.
- filepath( -- extracts the path from a combined path and filename.
- filerename -- renames and/or moves a file or folder.
- filesave -- saves data directly into a disk file.
- filesize( -- determines the size of any file on disk.
- filesuperdate( -- returns the modification date and time of a file.
- filetime( -- returns the modification time of a file.
- filetypecreator( -- returns the type and creator code of the specified file (if any).
- folder( -- creates a *Folder ID* that unambiguously describes the location of a folder on the hard disk.
- foldercontains( -- checks to see if a folder contains a specified file. See also the pathcontains( function.
- foldercontents( -- returns a list of all of the contents of a folder.
- foldercount( -- returns the total number of files within a folder (including any subfolders).
- folderexists( -- returns true if a folder exists, false if it does not.
- folderpath( -- converts a Folder ID into the HFS path of that folder.
- foldersepchar( -- returns the separator character used between folders.
- foldersize( -- calculates the size of a folder (in bytes).
- fullpath( -- converts a filename or relative path (starting with the : or / symbol) into a full HFS path, including the disk name.
- hfspath( -- converts a UNIX path into an HFS path.
- homepath( -- returns the HFS path of a subfolder of the current users home folder.
- homesubfolder( -- returns the folder id of a subfolder of the current user's home folder.
- hostedfiles( -- returns a list of open databases associated with a specified host (server).
- info("applicationsfolder") -- returns the path to the current user's Applications folder.
- info("applicationsupportfolder") -- returns the path to the current user's Application Support folder (inside the Library folder).
- info("cachefolder") -- returns the path to the current user's Cache folder (in the Library folder).
- info("desktopfolder") -- returns the path to the user's desktop folder.
- info("documentsfolder") -- returns the path to the current user's Documents folder.
- info("downloadsfolder") -- returns the path to the current user's Downloads folder.
- info("dropfiles") -- returns a list of files dragged onto a *Drag Receiver* form object (see Drag and Drop).
- info("foldersepchar") -- returns the separator character used between folders.
- info("libraryfolder") -- returns the path to the current user's Library folder.
- info("moviesfolder") -- returns the path to the current user's Movies folder.
- info("musicfolder") -- returns the path to the current user's Music folder.
- info("panoramafolder") -- returns the location of the folder containing the currently running copy of Panorama.
- info("picturesfolder") -- returns the path to the current user's Pictures folder.
- info("publicfolder") -- returns the path to the current user's Public folder.
- info("tempfolder") -- returns the path to the current user's temporary folder (for files you plan to use only for a short time).
- info("userfolder") -- returns the path to the current user's home folder.
- info("volumes") -- returns a list of all of the currently mounted volumes (disks) on the computer.
- listfiles( -- builds a text array listing the files in a folder.
- listpanoramafiles( -- returns a list of panorama database files in the specified folder.
- listtextfiles( -- returns a list of text files in the specified folder.
- makefolder -- creates a new folder, and if necessary, also creates any enclosing folders needed to create the specified new folder.
- makepackage -- creates a new package, and if necessary, also creates any enclosing folders needed to create the specified new package.
- modifyfileattributes -- modifies one or more attributes of a file (or folder).
- openanything -- opens a document or application.
- openfiledialog -- pauses and displays the standard “open file” dialog.
- openwith -- opens a document with a specific application.
- openwithterminal -- opens an application in a new Terminal.app window (useful for debugging).
- pathcontains( -- checks to see if a folder contains a specified file (or folder).
- pathcontents( -- lists the contents of a folder (specified by a path)
- pathexists( -- checks to see if a path exists.
- pathseparator( -- returns the type of separator character used in a file path (either / or :).
- posixpath( -- converts a path and filename into a POSIX path that can be used as a parameter to a shell command.
- revealinfinder -- reveals a file or folder in the Finder.
- revealmultipleinfinder -- reveals one or more files or folders in the Finder.
- savedialog -- displays a modal dialog that allows a user to specify the name and location of a new file.
- savefiledialog -- pauses a procedure and displays the standard “save file” dialog.
- subfolder( -- returns the folder id of a subfolder of a specified folder
- subpath( -- returns the HFS path of a subfolder of a specified folder.
- tempfolder( -- returns the path to the current user's temporary folder (for files you plan to use only for a short time).
- tildepath( -- converts a path in the current user's folder to tilde (~) notation.
- typecreatorcode( -- returns the 8 character TYPE and CREATOR codes for a filename (if any).
- uncompress -- uncompresses a `.zip`, `.tar.gz` or `.tar.bz2` file into a file or an entire folder.
- unixpath( -- converts an HFS path into a UNIX path.
- unixshellpath( -- converts a path and filename into a POSIX path that can be embedded within the shellscript statement.
- zipcompress -- compresses a file or an entire folder into a zip file (using ditto shell tool).
- zipuncompress -- uncompresses a file or an entire folder from a zip file (using ditto shell tool).

History

Version | Status | Notes
10.0 | Updated | Carried over from Panorama 6.0, but with significant changes, including the ability to handle UNIX style file paths in addition to HFS and changes to the way Folder IDs are handled.