- Perl ›
- File operation ›
- here
Get the current directory name
To get the current directory name, use the getcwd function of Cwd module.
use Cwd 'getcwd'; my $cur_dir = getcwd;
Example
This is an example to get the current directory name.
use strict; use warnings; use Cwd 'getcwd'; # Get the current directory name. print "1: Get the current directory name.\n"; my $cur_dir = getcwd; print $cur_dir, "\n";