[Chapter 13] 13.3 Making and Removing Directories
Author: Randal L. Schwartz, Erik Olson & Tom Christiansen
Date: 1999-07-02T01:35:28Z

#

| Chapter 13 File and Directory Manipulation |

## 13.3 Making and Removing Directories

You probably couldn't have made it this far without knowing about the mkdir or md command, which makes directories that hold other filenames and other directories. Perl's equivalent is the `mkdir` function, which takes a name for a new directory and a mode that will affect the permissions of the created directory. The mode is specified as a number interpreted in internal permissions format. For now, just say `0777` for the mode and everything will work. Here's an example of how to create a directory named `gravelpit`:

    mkdir("gravelpit",0777) || die "cannot mkdir gravelpit: $!";

The command-prompt rmdir command removes empty directories - you'll find a Perl equivalent with the same name (rmdir). Here's how to make Fred unemployed:

    rmdir("gravelpit") || die "cannot rmdir gravelpit: $!";

13.2 Renaming a File |  | 13.4 Modifying Permissions