How can I get a path without a file name in Windows using Perl?

I am looking to get a path without a file name in windows via perl

I have a full path as follows:

c:\My_Designs\ipcore_script\test\src\IP_CORE\mux\sus.do

I only need a path and you want to delete the file name, for example:

c:\My_Designs\ipcore_script\test\src\IP_CORE\mux

+4
source share
3 answers

Use File :: Basename

 > perl -MFile::Basename -wE "say dirname(qq(c:/perl/bin/perl.exe));" c:/perl/bin 
+7
source

You can also use Path :: Class :

 #!/usr/bin/env perl use strict; use warnings; use Path::Class; my $file = file('c:\My_Designs\ipcore_script\test\src\IP_CORE\mux\sus.do'); print $file->parent, "\n"; 

Output:

  C: \ My_Designs \ ipcore_script \ test \ src \ IP_CORE \ mux 
+5
source

You can also try this.

 $path='c:\My_Designs\ipcore_script\test\src\IP_CORE\mux\sus.do'; my $pathname=substr($path, 0, rindex($path,"\\")); Result: c:\My_Designs\ipcore_script\test\src\IP_CORE\mux 
0
source

Source: https://habr.com/ru/post/1385441/


All Articles