473,385 Members | 1,347 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PERL find files

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.  
Aug 11 '09 #1
9 3783
numberwhun
3,509 Expert Mod 2GB
@kanishka1213
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
Aug 11 '09 #2
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.  
Aug 11 '09 #3
KevinADC
4,059 Expert 2GB
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.
Aug 12 '09 #4
numberwhun
3,509 Expert Mod 2GB
@KevinADC
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
Aug 12 '09 #5
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.
Aug 12 '09 #6
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'
Aug 12 '09 #7
numberwhun
3,509 Expert Mod 2GB
@kanishka1213
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
Aug 12 '09 #8
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
Aug 12 '09 #9
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.
Aug 12 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: John Smith | last post by:
Hello, I have a rather odd question. My company is an all java/oracle shop. We do everything is Java... no matter what it is... parsing of text files, messaging, gui you name it. My question...
5
by: Premshree Pillai | last post by:
Hello, I recently wrote a Perl version of pyAlbum.py -- a Python script to create an image album from a given directory -- plAlbum.pl . It made me realize how easy-to-use Python is. ...
15
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python suppose you want to walk into a directory, say, to apply a string replacement to all html files. The os.path.walk() rises for the occasion. © import os ©...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
2
by: shruti | last post by:
hiii all I'm tryin to call a perl script from a C program in following 2 ways- 1.By callin system function. But there's some problem because the system function is not able to executeany...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.