learingperl01
MIS
Hello I was wondering what the best way to go about ignoring directories/files that are owned by the OS/system when using File:find:name
The problem that I am running into is that there are two/three directories/files that file:find:name can't get into or that when opening a filehandle fails b/c of permissions one of them being System Volume Information. So when file:find:name traverses to that directory the script fails and states permission denied.
I am using the code below along with other code, but the problem that I am encountering is like I mentioned running into files/directories which can't be read/opened mainly System Volume Information and pagefile.sys. I've tried adding the following but with no luck.
return if -r "$found_files";
If I run the script against a directory like my desktop or tmp directory it works just fine, just running into system files which i want to skip or ignore when they can't either be traversed or opened.
Thanks for help
The problem that I am running into is that there are two/three directories/files that file:find:name can't get into or that when opening a filehandle fails b/c of permissions one of them being System Volume Information. So when file:find:name traverses to that directory the script fails and states permission denied.
I am using the code below along with other code, but the problem that I am encountering is like I mentioned running into files/directories which can't be read/opened mainly System Volume Information and pagefile.sys. I've tried adding the following but with no luck.
return if -r "$found_files";
If I run the script against a directory like my desktop or tmp directory it works just fine, just running into system files which i want to skip or ignore when they can't either be traversed or opened.
Thanks for help
Code:
sub edits() {
if ( -f ) {
foreach ( $File::Find::name ) {
open(LOG, "< $File::Find::name") or die "Could not open file $_: $!";
while ( <LOG> ) {
my $LINE = $_;
if ( $LINE =~ m/$string/ ) {
print "Looking for: $string\n Found it in file: $LINE\n";
if ( $LINE =~ m/$updated_string/ ) {
print "Looking for: $updated_string\n Found it in file: $LINE\n";
}
}
}
}
}
else {
print "Could not find the second string: $updated_string\n";
}