Working with file paths and directories
Red by default uses the forward slash, /
, in some sort of universal path notation. The /
character denotes the root of the current drive, ./
denotes the current folder, and ../
points to the folder one step up in the file hierarchy. As we have seen in the guess-number.red
script from Chapter 4, Code-Controlling Structures, this ../
notation is used to denote a path relative to the current folder. An absolute path starts with a drive-letter or with the root drive /
.
Note
Use relative paths instead of absolute paths to make your scripts machine-independent. Also make sure that your program can run on Windows as well as on Linux or OS X.
Converting a string to a file is done with to-file
, but only the syntax changes, nothing else is checked.
If you need to transform a file path to a specific platform notation such as Windows, use the to-local-file
function, such as in the following:
;-- see Chapter07/working-with-files-directories.red: to-local-file%/E/Red...