I have a few sub-folders in the main folder. My program will do some calculations in each sub-folder. Firstly the code will create the "result" folder in main folder for all calculations. And, for the calculation in each sub-folder I want to create a folder in the "result" folder. But they should have the same name as sub-folder.
My working directory is "/home/abc/Desktop/test". The "test" is my main folder. There are "a", "b" and "c" sub-folders in "test" folder. My code creates the "result" folder in "test" main folder. But it also should create "a", "b" and "c" sub-folders in "result" folder. How can I fix my code?#!/usr/bin/env perl use strict; use warnings; use File::Path qw/make_path/; use Cwd; my $dir = cwd(); opendir (DIR, $dir) or die "Unable to open current directory! $!\n"; my @subdirs = readdir (DIR) or die "Unable to read directory! $!\n"; closedir DIR; my $result_path = "$dir/results"; make_path("$result_path"); foreach my $subdir ( sort @subdirs ) { chdir($subdir) or die "Cannot cd to $dir: $!\n"; make_path("$result_path/$subdir"); system("echo '1 0' | program -f methane.trr -o $result_path/$subdir/ou +tfile.txt"); chdir(".."); }
In reply to How to get sub-folder names using perl? by erhan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |