How to Make a Directory in Perl With a Script
The Perl programming language can interface with file systems, giving you the ability to read and write files and create folders. Creating directories using a Perl script can save you a lot of time. For example, if you use the same project file hierarchy for multiple projects, you can write a simple Perl script that creates the directories and use it multiple times. The Perl language has a built-in function that handles making directories. All you have to do is issue one statement to make a directory.
Instructions
-
-
1
Create a new text file using a word processor such as NotePad. Save the file using the '.plx' extension.
-
2
Open a command prompt and navigate to the folder where you saved the file created in the previous step. For example, if you saved your file on the root of your C:\ drive in Windows, you can type the following into a command prompt:
cd C:\
-
-
3
Make a folder named 'test' and give it read, write, and execute permissions to all users. Perl uses Unix permission masks (see Resource for more on Unix permissions). Under most circumstances, you will want to create folders with read, write, and execute permissions for at least one user. To create a folder with full access privileges, write the following statement in the source code file:
mkdir 'test', 777;
-
4
Execute the Perl script by issuing the following command from the command line, substituting the name you chose in Step 1 for 'filename':
perl filename.plx
-
5
Look in the directory where the script resides. There is a new folder labeled 'test' within this directory. Since this folder was created with full permissions, you can delete it unless it is needed for something.
-
1