Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

create a tree with mkpath

Status
Not open for further replies.

donny750

Programmer
Joined
Jul 13, 2006
Messages
145
Location
FR
hello,

I want to create a tree like this

home
dev1 test
dev2 file1
file2

in fact, like this
mkdir home
mkdir home/dev1
mkdir home/dev1/test
mkdir home/dev2
mkdir home/dev2/file1
mkdir home/dev2/file2

Is it necessary to repeat the path like
'home/dev2/'
??


My code :
Code:
#!/usr/bin/perl
 
use File::Path;
 
mkpath(['home/dev1/test', 'home/dev2/file1','home/dev2/file2'], 1);

Thanks
 
I'm not sure what your question is. Did your code not work?
 
my code work
but i want to know if it is like this i must to do to create directories or their are a best way ?
 
When you create 'home/dev1/test' it will create 'home', 'home/dev1' and 'home/dev1/test' if they haven't been created already. There's no need to create 'home' and 'home/dev1' seperately. Does that answer your question?
 
i don't make this
mkdir home
mkdir home/dev1
mkdir home/dev1/test
mkdir home/dev2
mkdir home/dev2/file1
mkdir home/dev2/file2

when i run my script
i see this in the shell
mkdir home
mkdir home/dev1
mkdir home/dev1/test
mkdir home/dev2
mkdir home/dev2/file1
mkdir home/dev2/file2
 
Yes, those are the commands that File::Path has to execute in order to create the paths that you've asked for. You don't need to specify the parent directories, but the module has to create them before it can create the subdirectories.
 
heu can you explain me
you say i can simplify this
Code:
#!/usr/bin/perl
 
use File::Path;
 
mkpath(['home/dev1/test', 'home/dev2/file1','home/dev2/file2'], 1);
 
No, you won't simplify it any more than that.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top