FreeKB - Perl (Scripting) File::Basename module
Perl (Scripting) - File::Basename module

In this example, the $file variable contains the absolute path to example.txt.

my $file = "/tmp/example.txt";


Printing the $file variable . . . 

print "$file \n";


. . . will return the absolute path to example.txt.



The File::Basename module can be used to create parse the filename and base directory. In this example, the $base_directory variable will contain a value of "/tmp" and the $file_name variable will contain a value of "example.txt".

my $base_directory = File::Basename::dirname($file);
my $file_name      = File::Basename::basename($file);


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter f9e1c in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |