Free Perl Tutorials

PERL rmdir function

Now that we have learned what the chdir and opendir functions do, it's time to learn how to delete a folder using PERL. Its easy to remove a directory using PERL. The important thing to remember is that PERL can only remove the folder or directory if the folder or directory is empty!

Here is an example of the code you would use to delete a folder using PERL:

#First, open your primary directory
opendir(DIR, 'test');

#Remove the unwanted folder (yes, keep the quotation marks)
rmdir 'name-of-unwanted-folder';

#close your directory
closedir(DIR);

You can now check your directory and see that the folder you wanted to delete is no longer there!