-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindGradientFiles.pl
93 lines (83 loc) · 2.35 KB
/
findGradientFiles.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl
###############################################################################
# Mina Jafari, June 2015 #
# Purpose: This script searches for all the string files in the directory you #
# have ran it and its subdirectories. It writes the name of the directory and #
# the output of "status" executable to a file named stringSummary.csv So you #
# can open it with excel. #
###############################################################################
use strict;
use warnings;
my $counter = 0;
my $path = shift || '.';
my @directories;
my @direc;
use Cwd;
my $pwd = getcwd();
my $outFile = "NEB-Gradients.csv";
my @outPuts;
my @array;
traverse($path);
#save the output of status exe in the outPuts array and copies the files to
#local machine
#my $desDir = "$I:Desktop/gradients"; #this should be entered manually
#my $num = sprintf("%04d", 0001);
my $output;
for my $j (@directories)
{
chdir "$j";
open FILE, 'gradient' or die $!;
while (<FILE>)
{
$output = $_;
}
close(FILE);
$j =~ s/\//-/g;
# system "scp -p gradient $desDir/$num-$j.txt"; #uncomment to copy files
# $num++;
my @directory = split /=/, $output;
my $dir2 = $directory[1];
$dir2 =~ s/ +/,/g;
push @outPuts, $dir2;
chdir "$pwd";
}
#combines the two arrays (outPuts and directories)
for my $i (0..$counter-1)
{
push @array, $directories[$i];
push @array, $outPuts[$i];
$i++;
}
#writes to the file
open FILE, ">", "$outFile" or die "can't open \n";
for my $k (@array)
{
print FILE $k, "\n";
print "\n\n";
}
close (FILE);
print("Total number of files = ", $counter, "\n");
#definition of traverse subroutine
sub traverse
{
my ($thing) = @_;
if ($thing =~ m/gradient$/)
{
$counter++;
#saves the path of the directories containing gradient files to
#@directories array
my $slashes = ($thing =~ tr/\///) - 1;
my @directory = split /\//, $thing;
my @dir2 = @directory[1..$slashes];
my $dir3 = join '/', @dir2;
push @directories, $dir3;
}
return if not -d $thing;
opendir my $dh, $thing or die;
while (my $sub = readdir $dh)
{
next if $sub eq '.' or $sub eq '..';
traverse("$thing/$sub");
}
close $dh;
}