erhan has asked for the wisdom of the Perl Monks concerning the following question:
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(".."); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get sub-folder names using Perl?
by Athanasius (Archbishop) on Mar 08, 2015 at 04:58 UTC | |
by erhan (Novice) on Mar 08, 2015 at 06:05 UTC | |
by Athanasius (Archbishop) on Mar 08, 2015 at 06:30 UTC | |
|
Re: How to get sub-folder names using perl?
by james28909 (Deacon) on Mar 08, 2015 at 01:53 UTC | |
by erhan (Novice) on Mar 08, 2015 at 05:49 UTC | |
by Laurent_R (Canon) on Mar 08, 2015 at 10:39 UTC | |
by Happy-the-monk (Canon) on Mar 08, 2015 at 10:54 UTC | |
by Laurent_R (Canon) on Mar 08, 2015 at 11:05 UTC | |
|
Re: How to get sub-folder names using perl?
by zwon (Abbot) on Mar 08, 2015 at 22:22 UTC |