n4narik
asked on
string manipulation
i have a path to a file: x:\dir1\dir2\test.txt < this path is generated dynamically.
i need a way to get only x:\dir1 from that string. i.e. get the drive and the first directory.
i need a way to get only x:\dir1 from that string. i.e. get the drive and the first directory.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$path =~ s/(.{3}[^\\]+)/$1/;
or use the File::Spec module:
use File::Spec;
($volume,$dirs,$file)=File
$dir1=(File::Spec->splitdi
$path="$volume\\$dir1";