in reply to how do I get the directory name from the pathnames
If you know the input will be of that form [as opposed to
c:\dir1\subdir1 (lowercase C:),
\dir1\subdir1 (no drive),
dir1\subdir1 (relative path) or
C:/dir1/subdir1 (alternate slashes)
], the following will do the trick:
my ($subdir1) = /^C:\\[^\\]+\\([^\\]+)/;
Otherwise, use core module File::Spec. (I don't see how File::Basename would help.)
use File::Spec (); my ($subdir1) = (File::Spec->splitdir(File::Spec->rel2abs($_)))[2];
|
|---|