469,336 Members | 5,552 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

Can i create a subdirectory using mkdir command?

i have made a directory c:/abcd
now i want to gather a list of sub directories from 1 directory and create the same list here.
i am able to print the list of sub directories,
but mkdir $dest/$_;
is not creating the subdirectory.
Please help
Jul 2 '08 #1
3 8083
The short answer is yes, you can create a subdirectory using Perl's mkdir command. Below is a small program that reads the STDIN for a string, and then appends that string to an existing directory. This new directory is passed to the mkdir() command.

Expand|Select|Wrap|Line Numbers
  1. $dest = "C:\\cygwin";
  2. while (<STDIN>) {
  3.    print "Making $dest\\$_\n";
  4.    chop;
  5.    mkdir "$dest\\$_";
  6. }
  7.  
Two things I noticed while coding up this example: 1) Even though I'm on Windows, I was able to run this code using "/" as the path separator, instead of "\" (which has to be escaped with another "\"). I leave this an exercise for you. 2) The chop() is necessary to remove the trailing newline from my input string. I noticed in the original post the presence of $_, and this could be an issue for you. If in doubt, print the "$_" value using print "[$_]", so you can see if your variable has leading or trailing characters.

Good luck.
Jul 3 '08 #2
numberwhun
3,503 Expert Mod 2GB
2) The chop() is necessary to remove the trailing newline from my input string. I noticed in the original post the presence of $_, and this could be an issue for you. If in doubt, print the "$_" value using print "[$_]", so you can see if your variable has leading or trailing characters..
Just a note, to clarify. chop() removes the last character in a string, regardless of what it is, and returns it. If what you are trying to do is remove the newline, then what you want to do is use chomp() which is far less invasive and ONLY removes what is defined in the special variable $/, which contains the current INPUT_RECORD_SEPARATOR.

Regards,

Jeff
Jul 3 '08 #3
KevinADC
4,059 Expert 2GB
i have made a directory c:/abcd
now i want to gather a list of sub directories from 1 directory and create the same list here.
i am able to print the list of sub directories,
but mkdir $dest/$_;
is not creating the subdirectory.
Please help
Post your perl code. Make sure to use the code tags when posting code.
Jul 3 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by musicloverlch | last post: by
7 posts views Thread by sieg1974 | last post: by
32 posts views Thread by munanxue | last post: by
4 posts views Thread by tomek | last post: by
5 posts views Thread by Michael Sperlle | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.