in reply to How can one create a text file in the subfolder of a folder?
Note the mkdir documentation states:
"To recursively create a directory structure, look at the make_path function of the File::Path module."
for example:
#!/usr/bin/perl use strict; use warnings; use File::Path qw(make_path); my $x='x'; my $y='y'; my $dirname = "$x/$y"; make_path( $dirname , { chmod => 0777, }); my $output="$dirname/z.txt"; open ( my $fh, ">", $output ) or die "Cannot open file '$output': $!\n +"; print $fh "\n It's ok.\n"; close $output; print "\n Program is over.\n";
Results:
D:\code>perl path.pl Program is over. D:\code>cd x/y D:\code\x\y>dir Volume in drive D is Data Volume Serial Number is 3241-B96B Directory of D:\code\x\y 22/04/2017 10:39 <DIR> . 22/04/2017 10:39 <DIR> .. 22/04/2017 10:39 13 z.txt 1 File(s) 13 bytes 2 Dir(s) 107,416,027,136 bytes free D:\code\x\y>cat z.txt It's ok. D:\code\x\y>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can one create a text file in the subfolder of a folder?
by supriyoch_2008 (Monk) on Apr 22, 2017 at 13:06 UTC |