Idem for the subdirectories:open IN, '<', 'clients.txt' or die "Can't open file 'clients.txt': $!" +; @clients = <IN>; chomp @clients;
open IN, '<', 'subdirectories.txt' or die "Can't open file 'subdirecto +ries.txt': $!"; @subdirs = <IN>; chomp @subdirs;
Now, it's time to "multiply" the clients with the subdirectories, meaning combining each of one array with each of the other array, and create the subdirectories for each result.
Note that perl actually doesn't mind you trying to create a directory that already exists.
my $year = 2005; mkdir $year, 0755; foreach my $client (@clients) { $client =~ /(\d*)\d/ or next; # we need digits; my $range = "${1}0_${1}9"; -d "$year/$range" or mkdir "$year/$range", 0755 or die "Can't create directory '$year/$range': $!"; -d "$year/$range/$client" or mkdir "$year/$range/$client", 0755 or die "Can't create directory '$year/$range/$client': $!"; foreach my $subdir (@subdirs) { -d "$year/$range/$client/$subdir" or mkdir "$year/$range/$clie +nt/$subdir", 0755 or die "Can't create directory '$year/$range/$client/$subdir +': $!"; } }
In reply to Re: How to automate construction of directories?
by bart
in thread How to automate construction of directories?
by absolutezero273c
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |