REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Concepts: Files: Names and Paths

Pending Revision

This document was written for R2 and has yet to be revised for R3.

REBOL provides a standard, machine independent file and path naming convention.


File Names

In scripts, file names and paths are written with a percent sign (%) followed by a sequence of characters:


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:


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.

Path Strings

File paths are written with a percent sign (%) followed by a sequence of directory names that are each separated by a forward slash (/).


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

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.

%"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 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:


would refer to a disk volume or partition named home. Other examples are:


To refer to the C volume that is often used by Windows, the notation is:

%"/c/program files/qualcomm/eudora mail/out.mbx"

Notice in the above lines that the disk volume, C, is not written as:


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:


Case Sensitivity

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.

File Name Functions

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-fileConverts strings and blocks into a file name or file path.
split-pathSplits a path into its directory part and its file name.
clean-pathReturns the absolute path that is equivalent to any given path containing double dot (..) or dot (.).
what-dirReturns the absolute path to the current directory.

  TOC < Back Next > - WIP Wiki Feedback Admin