# More on file specification

## Contents

- Using file specifications in OPL
- Current folder
- Control of folders

The internal memory and memory disks use a DOS-compatible directory structure, the same as that used on disks on PCs. However, the two machines differ quite considerably in this area as described below.

To specify a file completely, EPOC uses a drive (or device), folder and filename:

- The drive is the area on the machine where the file is kept. This can be `C:` (internal disk), `D:` (memory disk drive) `E:`,..., `Y:` or `Z:` (ROM).
- Every drive has one root folder, usually written as a backslash (`\`). This can "contain" files and/or other folders, each of which can contain more files and/or more folders. When you have "folders in folders" like this, they’re often called subfolders. Their names show where they are. For example, the root folder (`\`) could contain a folder called `\Jo`, which might in turn contain a folder called `\Jo\Backup`, which might contain some files.
- Filenames are composed of up to 256 characters (but see below), with an optional file extension comprised of a dot and one or more other characters. A filename may not begin with a back or forward slash (`\` or `/`) or a colon (`:`). Any trailing zeros on the filename are stripped.

The filing system does not treat extensions as a special component of a filename except when parsing (i.e. for `PARSE$`). You can also use long filenames with embedded spaces and any number of dots like: `OPL Reference manual` or `Very.long.filename`.

To specify a file completely, you add the three parts together. The folder part must end with a backslash. So an OPL module named `test`, in a folder called `\Jo` in the internal memory can be specified as `C:\Jo\test`. If this file were in the `\Jo\Backup` folder, it would be completely specified as `C:\Jo\Backup\Test`. If it were in the root folder, you would specify it as `C:\Test`.

A full file specification may be up to 255 characters long for OPL.

In OPL, as in other applications, the files are kept on the drive and in the folder you specify.

## Using file specifications in OPL

OPL commands which specify a filename, such as `OPEN`, `CREATE`, `gLOADBIT` and so on, can also use any or all of the other parts that make up a full file specification. (Normally, the only other part you might use is the drive name, if the file were on a memory disk.) So for example, `OPEN "C:\ADDR.TXT"` tries to open a file called `ADDR.TXT` in the root folder of the internal disk.

You can use the `PARSE$` function if you need to build up complex filenames. See Keyword Reference for more details of `PARSE$`.

## Current folder

The current folder for all commands is always `C:\` unless it has been changed by the command `SETPATH`. Hence any use of a keyword which takes a filename as an argument will only look in the current folder and so if this is other than `C:\`, it should be specified either by `SETPATH` or by including it in the filename. For example, to check whether the file `Program1` in the directory `D:\MyPrograms\` exists, either

        SETPATH "d:\MyPrograms\"
        ...
        IF EXISTS ("Program1")
        ...

or

        IF EXISTS ("d:\MyPrograms\Program1")
        ...

## Control of folders

Use the `MKDIR` command to make a new folder. For example, `MKDIR "C:\Mine\Temp"` creates a `C:\Mine\Temp` folder, also creating `C:\Mine` if it is not already there. An error is raised if the chosen folder exists already. Use `TRAP MKDIR` to avoid this.

`SETPATH` sets the current folder for file access - for example,

        SETPATH "C:\DOCUMENTS"

`LOADM` continues to use the folder of the running program, but all other file access will be to the newly specified folder.

Use `RMDIR` to remove a folder - for example, `RMDIR "C:\MINE"` removes the `MINE` folder on `C:`. A ‘Does not exist’ error is raised if the folder does not exist. Use `TRAP RMDIR` to avoid this. A ‘`File is in use`’ error will result if you try to remove a folder which contains open files.