perl - File search recursivly in the folders on windows -
trying write script search 2 file in folders once files found has perform operation on file :
i using windows script.
below hierarchy folders :
logs / | \ abc def xyz / \ / \ /\ anr etc anr etc anr etc
etc= text files.
what trying do:
i want check anr folder whether 2 files(pqr.txt , rst.txt) there or not, if files there operation on etc, have read 1 specific text file , search keywords in particular text file.
how approaching:
#!/bin/usr/perl -w use strict; use cwd; use file::find; $dir ="c:\aptscripts\apstress\logs"; find(\&file_operation,$dir); $first_file = @argv[0]; $sec_file= @argv[1]; sub file_operation { $file = $_; if(($file =~ /teaces/) && ($file =~ /traces.txt.bugreport/)) { opeartion } }
but logic not able whatever ma trying do. can body me out in this.
this 1 checks parent folder according description:
sub file_operation { $file = file::spec->rel2abs($_); if(($file =~ /traces/) && ($file =~ /traces.txt.bugreport/)) { ($parent) = ($file =~ m!(.*)/!); if (-f "$parent/anr/pqr.txt" or -f "$parent/anr/rst.txt") { print "do opeartion: $file $parent\n"; } } }
Comments
Post a Comment