Hi I am looking to get the path without the filename in perl

December 8, 2011 at 15:11:01
Specs: Windows 7

Hi I am looking to get the path without the filename in windows through perl
I have the full path like this
c:\My_Designs\ipcore_script\test\src\IP_CORE\mux\sus.pl
I need only the path and want to strip off the filenmae like
c:\My_Designs\ipcore_script\test\src\IP_CORE\mux
Please help me
Thanks
Mitt

See More: Hi I am looking to get the path without the filename in perl

Report •

#1
December 8, 2011 at 17:37:54
I am not a WIndow's perl programmer, but you might be able to use the perl sub routines defined here:

http://snippets.dzone.com/posts/sho...

In my opinion, because the Unix/Linux path delimier is / instead of \ as in windows, you'll probably have to change this:

sub dirname($) {my $file = shift; $file =~ s!/?[^/]*/*$!!; return $file; }

to something like this:

# UNTESTED!!
sub dirname($) {my $file = shift; $file =~ s!\?[^\]*\*$!!; return $file; }

If this doesn't work, it might be because \ is treated as an escape sequence. you might try:

# UNTESTED!!
sub dirname($) {my $file = shift; $file =~ s!\\?[^\\]*\*$!!; return $file; }


Report •

#2
December 9, 2011 at 01:17:46
Use the File::Basename module ( http://search.cpan.org/~flora/perl-... ), which was written to solve this sort of problem. Perl has a host of modules to solve just about every requirement that you may have.

Report •
Related Solutions


Ask Question