in reply to Re: get folder name only
in thread get folder name only

Something was bugging me about this, basename returns nothing if the path ends with a dir separator. This will deal with that:

#! /usr/bin/perl -w use strict; use File::Basename; # Test data my @dirs = ( 'c:/mail/test2', 'c:/mail', 'c:/mail/test2/', 'c:/mail/', ); foreach (@dirs) { print "before: $_ "; # Strip off the trailing / # Warning: may not be platform independent s|/$||; print "after: " . basename $_ . $/; }