Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I find the parent directory of a file in Perl?

Tags:

directory

perl

Is there some function that returns the parent directory of a file in Perl?

like image 588
Zerobu Avatar asked Apr 02 '10 01:04

Zerobu


People also ask

How do I get the parent directory of a file?

Use File 's getParentFile() method and String. lastIndexOf() to retrieve just the immediate parent directory.

How do I get the directory of a file in Perl?

The dirname() method in Perl is used to get the directory of the folder name of a file.

What is the parent directory of a file?

With a directory, a parent directory is a directory containing the current directory. For example, in the MS-DOS path below, the "Windows" directory is the parent directory of the "System32" directory, and C:\ is the root directory.

How do I navigate to a parent directory?

There is no way to go to the parent folder right out of the search results, as that is not how it operates, however if you double-click on the quick launch search result, resulting in navigating to the folder, then press alt+up then it will go to the parent folder.


1 Answers

If you have a path name, you can use the dirname function from File::Basename.

 use File::Basename;
 my $directory = dirname( $path );

What do you have as input?

like image 142
brian d foy Avatar answered Sep 24 '22 04:09

brian d foy