REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
REBOL provides a standard, machine independent file and path naming convention.
In scripts, file names and paths are written with a percent sign (%) followed by a sequence of characters:
%examples.r %big-image.jpg %graphics/amiga.jpg %/c/plug-in/video.r %//sound/goldfinger.mp3
The percent sign is necessary to prevent file names from being interpreted as words within the language.
Although it is not a good practice, spaces can be included in file names by enclosing the file name in double quotes (" "). The double quotes prevent the file name from being interpreted as multiple words:
%"this file.txt" %"cool movie clip.mpg"
The standard Internet convention of using a percent sign (%) and a hex code is also allowed for character encoding. When this is done, quotes are not required. The above file names could also be written as:
%this%20file.txt %cool%20movie%20clip.mpg
Note that the standard file suffix for REBOL scripts is ".r". On systems where this convention collides with another file type, a ".reb" suffix can be used instead.
File paths are written with a percent sign (%) followed by a sequence of directory names that are each separated by a forward slash (/).
%dir/file.txt %/file.txt %dir/ %/dir/ %/dir/subdir/ %../dir/file.txt
The standard character for separating directories is the forward slash (/), not the backslash (\). If backslashes are found they are converted to forward slashes:
probe %\some\cool\movie.mpg
%/some/cool/movie.mpg
REBOL provides a standard, operating system independent method for specifying directory paths. Paths can be relative to the current directory or absolute from the top-level file structure of the operating system.
File paths that do not begin with a forward slash (/) are relative paths.
%docs/intro.txt %docs/new/notes.txt %"new mail/inbox.mbx"
The standard convention of using double dots (..) to indicate a parent directory or a single dot (.) to refer to the current directory is also supported. For example:
%. %./ %./file.txt %.. %../ %../script.r %../../plans/schedule.r
File paths use the standard Internet convention of beginning absolute paths with a forward slash (/). The forward slash indicates to start at the top level of the file system. (Generally, absolute paths should be avoided to ensure machine-independent scripts.) The example:
%/home/file.txt
would refer to a disk volume or partition named home. Other examples are:
%/ram/temp/test.r %/cd0/scripts/test/files.r
To refer to the C volume that is often used by Windows, the notation is:
%/C/docs/file.txt %"/c/program files/qualcomm/eudora mail/out.mbx"
Notice in the above lines that the disk volume, C, is not written as:
%c:/docs/file.txt
The above example is not a machine independent format and causes an error.
If the first directory name is absent, and the path begins with double forward slashes (//), then the file path is relative to the current volume:
%//docs/notes
In REBOL, file names are not case-sensitive by default. However, when new files are created by the language, they keep the case they were typed in:
write %Script-File.r file-data
The above example creates the file name with the S and F in uppercase.
In addition, when file names are read from directories, the case is preserved:
print read %/home
For case-sensitive systems, such as UNIX, REBOL finds the closest case match to the specified file. For example, if a script asks to read %test.r, but only finds %TEST.r, the %TEST.r file is read. This behavior is necessary to allow machine-independent scripts.
Various functions are provided to help you create file names and paths. These are listed below in [bad-link:concepts/file.txt] Name Functions.
to-file | Converts strings and blocks into a file name or file path. |
split-path | Splits a path into its directory part and its file name. |
clean-path | Returns the absolute path that is equivalent to any given path containing double dot (..) or dot (.). |
what-dir | Returns the absolute path to the current directory. |
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |