Creating a directory
To create a directory, simply pass the name of the directory to DIR(). This name can include the full path to the new directory (to be created). For example to create a directory named MyDir on the C drive inside of some directory named Something, you would pass C:\Something\MyDir. (It is also acceptable to put a trailing backslash upon the name, such as C:\Something\MyDir\).
If DIR() succeeds in creating the directory, it returns an empty string. If there is a problem, then an error message is returned instead.
/* Create the MyDir directory inside C:\Something. */ error = DIR('C:\Something\MyDir') /* Note: 'C\Something\MyDir\' is also ok. */ /* Display any error. */ IF error \= "" THEN SAY errorNote: If the directory you wish to create already exists, this is not considered an error, and DIR() will return an empty string in this case.
DIR() will ensure that all of the other directories in the name exist. If they do not exist, DIR() will automatically create them. In the above example, if the directory Something didn't already exist upon the C drive, then DIR() would automatically create it, and then create MyDir inside it.
If you wish to create the directory inside of whatever the current directory is, then you may specify only the name of the new directory, for example, MyDir.
/* Create the MyDir directory in the current directory. */ error = DIR('MyDir') /* Note: 'MyDir\' is also ok. */ /* Display any error. */ IF error \= "" THEN SAY errorHere we create a new directory MyDir inside of the Something directory in the current directory. If Something doesn't already exist in the current directory, it will be created there as well.
/* Create Something\MyDir directory in the current directory. */ error = DIR('Something\MyDir') /* Display any error. */ IF error \= "" THEN SAY error
Deleting a directory
DIR() can also delete a directory. To do this, you must pass a second arg of 'D'.
/* Delete the MyDir directory inside C:\Something. */ error = DIR('C:\Something\MyDir', 'D') /* Note: 'C\Something\MyDir\' is also ok. */ /* Display any error. */ IF error \= "" THEN SAY errorDIR() does not delete any of the parent directories. In the above example, DIR() does not delete the directory Something. It deletes only the directory MyDir.
Note: DIR() will not delete a directory that contains any files or sub-directories. You must first delete the contents of the directory before calling DIR().