in reply to mkdir problem on windows
A simple explanation to the code above: We use split to get a list of folder names ( if you want the user to supply the folder names be sure to check if he used a slash ( / ) or a backslash ( \ ) you will have to modify the regular expression in split for this ).#!/usr/bin/perl use warnings; use strict; my $foldername = "Test1/Test2"; my @folders = split /\//,$foldername; for (0 .. $#folders) { mkdir -p $folders[$_]; chdir $folders[$_]; }
I think that using map will work faster here, and also i modified the regular expression in split so it handles both directories delimited with / and \, it works fine on my windows xp.#!/usr/bin/perl use warnings; use strict; my $foldername = "Test1/Test2"; my @folders = split /\/|\\/, $foldername; map { mkdir $_; chdir $_; } @folders;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: mkdir problem on windows
by Tanalis (Curate) on Sep 19, 2005 at 13:51 UTC | |
by graff (Chancellor) on Sep 19, 2005 at 18:07 UTC |