- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create, Delete and Change Directories in Perl
You can use mkdir function in Perl to create a new directory. You will need to have the required permission to create a directory.
#!/usr/bin/perl $dir = "/tmp/perl"; # This creates perl directory in /tmp directory. mkdir( $dir ) or die "Couldn't create $dir directory, $!"; print "Directory created successfully\n";
Remove a directory
You can use rmdir function in Perl to remove a directory. You will need to have the required permission to remove a directory. Additionally this directory should be empty before you try to remove it.
#!/usr/bin/perl $dir = "/tmp/perl"; # This removes perl directory from /tmp directory. rmdir( $dir ) or die "Couldn't remove $dir directory, $!"; print "Directory removed successfully\n";
Change a Directory
You can use chdir function in Perl to change a directory and go to a new location. You will need to have the required permission to change a directory and go inside the new directory.
#!/usr/bin/perl $dir = "/home"; # This changes perl directory and moves you inside /home directory. chdir( $dir ) or die "Couldn't go inside $dir directory, $!"; print "Your new location is $dir\n";
- Related Articles
- Copy, Rename and Delete Files in Perl
- Database DELETE Operation in Perl
- Create directories recursively in Java
- How to create directories (hierarchically) in Java?
- C# Program to create new directories
- Create References in Perl
- How to create Array in Perl?
- How to create Directories using the File utility methods in Java?
- How to create Database Connection in Perl?
- How to get all the directories and sub directories inside a path in C#?
- Directories in Python
- Create a Report Header using Perl
- Listing out directories and files in Python?
- Listing out directories and files using C#
- Generate temporary files and directories using Python

Advertisements