Connecting Tech Pros Worldwide Forums | Help | Site Map

PERL find files

Newbie
 
Join Date: Jul 2009
Posts: 22
#1: Aug 11 '09
i want to find files in a directory that can have multiple dots. like

Could not open 'Streams/Allegro_FUNNY_A_00_HD2_10.4.trp'
Could not open 'Streams/Allegro_FUNNY_B_00_HD2_10.4.ts'
Could not open 'Streams/Allegro_POC_CAVLC_00_5x6_10.3.ts'
Could not open 'Streams/C40UDTA.b.trp'

i could parse all other streams well but couldnt open the onces that had more than one dot.can any one correct my regex pattern?

Expand|Select|Wrap|Line Numbers
  1. if(/\w+\...(dts|ts|trp|mpg|TRP)/) 
  2.  
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,569
#2: Aug 11 '09

re: PERL find files


Quote:

Originally Posted by kanishka1213 View Post

i want to find files in a directory that can have multiple dots. like

Could not open 'Streams/Allegro_FUNNY_A_00_HD2_10.4.trp'
Could not open 'Streams/Allegro_FUNNY_B_00_HD2_10.4.ts'
Could not open 'Streams/Allegro_POC_CAVLC_00_5x6_10.3.ts'
Could not open 'Streams/C40UDTA.b.trp'

i could parse all other streams well but couldnt open the onces that had more than one dot.can any one correct my regex pattern?

Expand|Select|Wrap|Line Numbers
  1. if(/\w+\...(dts|ts|trp|mpg|TRP)/) 
  2.  

Well, I changed your regex to be:

Expand|Select|Wrap|Line Numbers
  1. /\w+.*(dts|ts|trp|mpg|TRP)/
  2.  
That matched (as did yours), so I am not sure what is going on. You need to share the rest of your code so we can see what's going on. The errors you gave were errors opening the files, not matching. Please provide the rest of your code so we may see what is happening.

Regards,

Jeff
Newbie
 
Join Date: Jul 2009
Posts: 22
#3: Aug 11 '09

re: PERL find files


Expand|Select|Wrap|Line Numbers
  1. #!/perl/bin/perl
  2.  
  3. use CGI qw(:standard);
  4. use CGI::Carp qw(fatalsToBrowser);
  5. use File::Basename;
  6. use File::Find;
  7. print header;
  8.  
  9. my @unparsed_files;
  10. my $parser_tool_dir="C:/Program Files/Manzanita Systems/MP2TSA 3";
  11. my $dir="F:";
  12.  
  13. my ($stream_name,$stream_loc,$htmlstream,$stream,$txtstream,$docstream);
  14. my $count_present=0;
  15. my $count_absent=0;
  16. my $count_total=0;
  17.  
  18. find(\&edits,$dir);
  19.  
  20. sub edits
  21. {
  22.     #Finds files with following extensions
  23.     if(/\w+\.(dts|ts|trp|mpg|TRP)/)  
  24.     {
  25.         $count_total++;                 #count the number of files found
  26.         $stream_name=$_;
  27.  
  28.         #name of stream
  29.         $stream_loc=$File::Find::name;  #path of stream
  30.  
  31.         my($stream_name, $stream_loc) = fileparse($stream_loc);
  32.  
  33.         $stream_name=~ s/\..*//; #stripping off the stream extension
  34.         $htmlstream=$stream_loc.$stream_name.".html";  #appending html extsion
  35.         $txtstream=$stream_loc.$stream_name.".txt";
  36.         $docstream=$stream_loc.$stream_name.".doc";
  37.         if((-e $htmlstream)||(-e $txtstream)|| (-e $docstream))
  38.         {
  39.             $count_present++;         #streams are present
  40.         }
  41.         else
  42.         {
  43.             $stream=$File::Find::name;
  44.             $count_absent++;          #streams are absent
  45.             push(@unparsed_files,$stream);    
  46.         }
  47.     }
  48. }
  49.  
  50. my ($stream_file,$html_file);
  51.  
  52. find(\&analyze,$parser_tool_dir);
  53. sub analyze
  54. {
  55.     if($_ eq 'mp2tsa.exe')
  56.     {
  57.         foreach $stream_file(@unparsed_files)
  58.         {        
  59.             $html_file=$stream_file;
  60.             $html_file=~ s/\..*//;         #stripping off extension
  61.             $html_file=$html_file.".html";
  62.             my $status = system("mp2tsa.exe -o $html_file $stream_file");
  63.         }
  64.     }
  65. }
  66. print "<BR>Scanning Directory: $dir";
  67. print "<BR>Total Streams Scanned: $count_total";
  68. print "<BR>Parsed Streams Found : $count_present";
  69. print "<BR>Unparsed Streams Found: $count_absent";        
  70.  
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#4: Aug 12 '09

re: PERL find files


the multiple dots seem to have nothing to do your problem. It appears you are trying to match certain file extensions so you should anchor the regexp to the end of the string:

Expand|Select|Wrap|Line Numbers
  1. if(/\.(dts|ts|trp|mpg|TRP)$/)
The error "Could not open" appears to be coming from the system() call and not anything to do with perl.
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,569
#5: Aug 12 '09

re: PERL find files


Quote:

Originally Posted by KevinADC View Post

the multiple dots seem to have nothing to do your problem. It appears you are trying to match certain file extensions so you should anchor the regexp to the end of the string:

Expand|Select|Wrap|Line Numbers
  1. if(/\.(dts|ts|trp|mpg|TRP)$/)
The error "Could not open" appears to be coming from the system() call and not anything to do with perl.

See, that's why I wanted to see the code, because a regex would not cause an open failure message.

I agree with Kevin, whatever that program is, that is causing the issue. It might be path related or permissions, so look into that.

Regards,

Jeff
Newbie
 
Join Date: Jul 2009
Posts: 22
#6: Aug 12 '09

re: PERL find files


yes. i also think the same.
but when i try to on the normal windows command line the same call on those files that couldnt open , they open also, get analysed and their relative html is also produced.

when i works fine wiht windows cmd line. i dnt understand y the same command doesnt work when embedded as a system call in perl program.
Newbie
 
Join Date: Jul 2009
Posts: 22
#7: Aug 12 '09

re: PERL find files


and u know what not all files are giving this error.
some of them run and some of them gives error.
strange !!!!!!!!
Could not open '2.mpg'
Could not open '2.mpg'
Could not open 'lipsync/64QAM_t0508-old3.trp'
Could not open 'lipsync/64QAM_t0508-old3.trp'
Could not open 'lipsync/64QAM_t0508-old4.trp'
Could not open 'lipsync/64QAM_t0508-old4.trp'
Could not open 'lipsync/64QAM_t0508-old5.trp'
Could not open 'lipsync/64QAM_t0508-old5.trp'
Could not open 'lipsync/64QAM_t0508-old6.trp'
Could not open 'lipsync/64QAM_t0508-old6.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480i.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480i.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480p.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480p.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync720p.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync720p.trp'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC1080i.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC1080i.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC480p.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC480p.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC720p.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC720p.TRP'
Could not open '204.mpg'
Could not open '204.mpg'
Could not open 'Streams/2_dialnormswp..trp'
Could not open 'Streams/2_dialnormswp..trp'
Could not open 'Streams/2_dvblevel_ddp..trp'
Could not open 'Streams/2_dvblevel_ddp..trp'
Could not open 'Streams/2_k5compress..trp'
Could not open 'Streams/2_k5compress..trp'
Could not open 'Streams/2_ref997..trp'
Could not open 'Streams/2_ref997..trp'
Could not open 'Streams/acmod1_0..trp'
numberwhun's Avatar
Site Moderator
 
Join Date: May 2007
Location: New Hampshire
Posts: 2,569
#8: Aug 12 '09

re: PERL find files


Quote:

Originally Posted by kanishka1213 View Post

and u know what not all files are giving this error.
some of them run and some of them gives error.
strange !!!!!!!!
Could not open '2.mpg'
Could not open '2.mpg'
Could not open 'lipsync/64QAM_t0508-old3.trp'
Could not open 'lipsync/64QAM_t0508-old3.trp'
Could not open 'lipsync/64QAM_t0508-old4.trp'
Could not open 'lipsync/64QAM_t0508-old4.trp'
Could not open 'lipsync/64QAM_t0508-old5.trp'
Could not open 'lipsync/64QAM_t0508-old5.trp'
Could not open 'lipsync/64QAM_t0508-old6.trp'
Could not open 'lipsync/64QAM_t0508-old6.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480i.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480i.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480p.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync480p.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync720p.trp'
Could not open 'lipsync/Lipsync_TestStreams/64QAM_lipsync720p.trp'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC1080i.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC1080i.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC480p.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC480p.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC720p.TRP'
Could not open 'lipsync/Lipsync_TestStreams/LIPSYNC720p.TRP'
Could not open '204.mpg'
Could not open '204.mpg'
Could not open 'Streams/2_dialnormswp..trp'
Could not open 'Streams/2_dialnormswp..trp'
Could not open 'Streams/2_dvblevel_ddp..trp'
Could not open 'Streams/2_dvblevel_ddp..trp'
Could not open 'Streams/2_k5compress..trp'
Could not open 'Streams/2_k5compress..trp'
Could not open 'Streams/2_ref997..trp'
Could not open 'Streams/2_ref997..trp'
Could not open 'Streams/acmod1_0..trp'

Again, is it a path issue? Where is the script sitting in relation to these paths? From what I see, it would have to be in the parent directory and all these would have to be subdirectories of that parent. You may want to consider using absolute paths to avoid this issue.

Regards,

Jeff
Newbie
 
Join Date: Jul 2009
Posts: 22
#9: Aug 12 '09

re: PERL find files


Thanks Jeff,

i noticed the same. i copied some of the files that were in error list in one folder in c drive and it parsed all files perfectly. so the issue is when the depth of the folder gets larger the tool is not able to find it . c the folder depth.
"F:\Audio\Audio\lipsync-sharlik\new lipsync\Lipsync_TestStreams\unparsedfile.trp". so you mean to say i should use absolute paths.
but i scan entire F: drive as u see in the code. so i just named dir path as "F:".. and the path of the stream is
"F:/Audio/Dolby DD+/DD+ Streams/acmodswp.trp" is this not absolute path? m sorry my concepts are not so clear regarding this..

thanks for the real quick answer
Newbie
 
Join Date: Jul 2009
Posts: 22
#10: Aug 12 '09

re: PERL find files


No pain to analyze the problem any more. i got the solution. its works fine now. thanks Jeff and Kevin again. I really appreciate your help.
Reply