
CHAPTER 3: File System Access Using File and Folder objects 40
Absolute and relative path names
An absolute path name in URI notation describes the full path from a root directory down to a specific file
or folder. It starts with one or two slashes (
/), and a slash separates path elements. For example, the
following describes an absolute location for the file
myFile.jsx:
/dir1/dir2/mydir/myFile.jsx
A relative path name in URI notation is appended to the path of the current directory, as stored in the
globally available
current property of the Folder class. It starts with a folder or file name, or with one of
the special names dot (
.) for the current directory, or dot dot (..) for the parent of the current directory. A
slash (
/) separates path elements. For example, the following paths describe various relative locations for
the file
myFile.jsx:
Relative path names are independent of different volume names on different machines and operating
systems, and therefore make your code considerably more portable. You can, for example, use an absolute
path for a single operation, to set the current directory in the
Folder.current property, and use relative
paths for all other operations. You would then need only a single code change to update to a new platform
or file location.
Character interpretation in paths
There are some platform differences in how pathnames are interpreted:
X On Windows and Mac OS, path names are not case sensitive. In UNIX, paths are case sensitive.
X On Windows, both the slash (/) and the backslash (\) are valid path element separators. Backslash is
the escape character, so you must use a double backslash (
\\) to indicate the character.
X On Mac OS, both the slash (/) and the colon (:) are valid path element separators.
If a path name starts with two slashes (or backslashes on Windows), the first element refers to a remote
server. For example,
//myhost/mydir/myfile refers to the path /mydir/myfile on the server myhost.
URI notation allows special characters in pathnames, but they must specified with an escape character (
%)
followed by a hexadecimal character code. Special characters are those which are not alphanumeric and
not one of the characters:
/ - — . ! ~ * ' ( )
A space, for example, is encoded as %20, so the file name "my file" is specified as "my%20file". Similarly,
the character
ä is encoded as %E4, so the file name "Bräun" is specified as "Br%E4un".
This encoding scheme is compatible with the global JavaScript functions
encodeURI and decodeURI.
myFile.jsx
./myFile.jsx
In the current directory.
../myFile.jsx
In the parent of the current directory.
../../myFile.jsx
In the grandparent of the current directory.
../dir1/myFile.jsx
In dir1, which is parallel to the current directory.
Kommentare zu diesen Handbüchern