REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 26-Jan-2010 Edit History  

REBOL 3 Datatypes: File!



The file! datatype can be a file name, directory name, or directory path.


File values are a subset of series, and thus can be manipulated as a series:

probe find %dir/path1/path2/file.txt "path2"
f: %dir/path/file.txt
probe head remove/part (find f "path/") (length? "path/")


Files are designated with a percent sign (%)followed by a sequence of characters:

load %image.jpg
prog: load %examples.r
save %this-file.txt "This file has few words."
files: load %../programs/

Unusual characters in file names must be encoded with a % hexadecimal number, which is an Internet convention. A file name with a space (hexadecimal 20) would look like:

probe %cool%20movie%20clip.mpg
print %cool%20movie%20clip.mpg
cool movie clip.mpg

Another format is to enclose the file name in quotes:

probe %"cool movie clip.mpg"
print %"cool movie clip.mpg"
cool movie clip.mpg

The standard character for separating directories in a path is the forward slash (/), not the backslash (\). However, the REBOL language automatically converts backslashes found in file names to forward slashes:

probe %\some\path\to\some\where\movieclip.mpg


The to-file function converts data to the file! datatype:

probe to-file "testfile"

When passed a block, elements in the block are concatenated into a file path with the final element used as the file name:

probe to-file [some path to a file the-file.txt]


Use file? to determine whether a value is an file! datatype.

probe file? %rebol.r

As files are a subset of the series! pseudotype, use series? to check this:

probe series? %rebol.r

  TOC < Back Next > - WIP Wiki Feedback Admin