-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindFileNames.pl
More file actions
129 lines (105 loc) · 2.78 KB
/
findFileNames.pl
File metadata and controls
129 lines (105 loc) · 2.78 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/perl
#
##!/usr/bin/perl
#
#
# This software was developed and is maitained by :
#
# J.P. Langan
# 13186 15th Street South
# Afton, MN 55001
#
# Support inquiries to softw-dev@dyn-eng.com
#
#
# please remit all bug reports to support email address
#
# Bugs will be fixed, enhancements considered
#
use strict;
use warnings;
my @dStack;
#
# a few global variables
#
my $sStrng = "";
my $iCase = "n";
my $num_args = @ARGV;
my $idx;
my $fileCnt = 0;
my $stackSz = 0;
sub getDirectory {
my $dPath = $_[0];
my $str = $_[1];
my $fSuffix = $_[2];
my $indx;
#print "Testing Directory... $dPath\n";
# Open the directory
opendir(my $dh, $dPath) or die "Cannot open directory '$dPath': $!";
# Read the contents of the directory
my @files = readdir($dh);
for($indx = 0; $indx < @files; $indx++) {
$_ = $files[$indx];
$fileCnt++;
if(! (length($files[$indx]) <= 2 && (/\./ || /\.\./)) && ! -l $dPath.$files[$indx]) {
if(-f $dPath.$files[$indx]){
#print " ...common file\n";
# test for content and file type print results if a match
#testFile($dPath . $files[$indx]);
$_ = $files[$indx];
if(/$sStrng/i) {print "matched ...$dPath$files[$indx]\n\n";}
}
if(-d $dPath.$files[$indx]) {
$_ = $dPath . $files[$indx]. "/";
push @dStack, $_; #print " ...directory\n";
}
}
}
# Close the directory handle
closedir($dh);
}
#
#
#
# searchFiles - search files and scan tranverse directories for files containing and input string
#
# 2025-10-19 - jpl Original Version
#
# Only known deficiency is this version won't traverse logical links
#
# Inputs -d "directory name" base directory for beginning of search
# -s "search string" string to search in suspect file names
#
#
# 2025-10-17 - jpl Added code to close the input directory with a "/" automatically
##
# 2025-10-17 - jpl Rearranged code to eliminate the possiblility of cyclic tranversing of symbolic links
# Program now works on all directories. Was crashing...
#
#
#
# Parse out the input selections and parameters from the user
#
my $fNameTest = "";
my $stackNo = 0;
my $rDir = "";
print "Number of input arguments $num_args\n\n";
for($idx = 0; $idx < $num_args; $idx++) {
$_ = lc($ARGV[$idx]);
print "Argv : $_\n";
if(/^-s(.*)/) {$sStrng = $1;}
if(/-i/) {$iCase = "y";}
if(/-d(.*)/) {$rDir = $ARGV[$idx]; $rDir =~ s/^-d//;}
}
print "Search String :|$sStrng|\n";
$_ = $rDir;
if(! /\/$/) {$rDir .= "/";}
push @dStack, $rDir;
while(1) {
$fNameTest = pop @dStack;
getDirectory($fNameTest); # pack the stack with first directory names
$stackNo = @dStack;
if($stackNo == 0) {print "\n\nProcessing complete! number of files evaluated $fileCnt \n\n\n"; exit 0;}
}
print "\n\nProcessing complete!\n\n\n";
exit 0;