Welcome to the Monastery | |
PerlMonks |
Re: mkdir problem on windowsby mulander (Monk) |
on Sep 19, 2005 at 12:59 UTC ( [id://493143]=note: print w/replies, xml ) | Need Help?? |
Hello fellow Monk. First of all do not create directories using the system command, instead use perl build in mkdir(); function. I understand that you want to create directories recursiv, in example if provided Test1/Test2 you want the Test1 directory to be created first and then Test2 created inside of Test1, did I get it right? If so here is a simple script that I wrote as an example for your case, it does the job but probably can be better written. 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 ). The for loop iterates over the entire list, as you can see inside every iteration we create a directory using mkdir function of perl, and chdir function ( also build in ) to descend into the newly created directory. The loop stops when it creates the last directory from the list. I do not know why you tried to use the -p switch on the call to windows mkdir, as far as I remember, windows does not support switches on its command line, so you would just create a directory '-p'. I tested my script on windows xp, and it work the way it is supposed to :) hope I this reply will help you at least a bit, or give a new view on the subject. PS. I came up with another way to get the job done and here it is: 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.
In Section
Seekers of Perl Wisdom
|
|