PERL find files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kanishka1213
    New Member
    • Jul 2009
    • 22

    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.tr p'
    Could not open 'Streams/Allegro_FUNNY_B _00_HD2_10.4.ts '
    Could not open 'Streams/Allegro_POC_CAV LC_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?

    Code:
    if(/\w+\...(dts|ts|trp|mpg|TRP)/)
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    Originally posted by kanishka1213
    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.tr p'
    Could not open 'Streams/Allegro_FUNNY_B _00_HD2_10.4.ts '
    Could not open 'Streams/Allegro_POC_CAV LC_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?

    Code:
    if(/\w+\...(dts|ts|trp|mpg|TRP)/)
    Well, I changed your regex to be:

    Code:
    /\w+.*(dts|ts|trp|mpg|TRP)/
    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

    Comment

    • kanishka1213
      New Member
      • Jul 2009
      • 22

      #3
      here is the code.. Thanks

      Code:
      #!/perl/bin/perl
      
      use CGI qw(:standard);
      use CGI::Carp qw(fatalsToBrowser);
      use File::Basename;
      use File::Find;
      print header;
      
      my @unparsed_files;
      my $parser_tool_dir="C:/Program Files/Manzanita Systems/MP2TSA 3";
      my $dir="F:";
      
      my ($stream_name,$stream_loc,$htmlstream,$stream,$txtstream,$docstream);
      my $count_present=0;
      my $count_absent=0;
      my $count_total=0;
      
      find(\&edits,$dir);
      
      sub edits
      {
      	#Finds files with following extensions
      	if(/\w+\.(dts|ts|trp|mpg|TRP)/)  
      	{
      		$count_total++;	     		#count the number of files found
      		$stream_name=$_;
      		
      		#name of stream
      		$stream_loc=$File::Find::name;  #path of stream
      	
      		my($stream_name, $stream_loc) = fileparse($stream_loc);
      		
      		$stream_name=~ s/\..*//; #stripping off the stream extension
      		$htmlstream=$stream_loc.$stream_name.".html";  #appending html extsion
      		$txtstream=$stream_loc.$stream_name.".txt";
      		$docstream=$stream_loc.$stream_name.".doc";
      		if((-e $htmlstream)||(-e $txtstream)|| (-e $docstream))
      		{
      			$count_present++; 		#streams are present
      		}
      		else
      		{
      			$stream=$File::Find::name;
      			$count_absent++;  		#streams are absent
      			push(@unparsed_files,$stream);	
      		}
      	}
      }
      
      my ($stream_file,$html_file);
      
      find(\&analyze,$parser_tool_dir);
      sub analyze
      {
      	if($_ eq 'mp2tsa.exe')
      	{
      		foreach $stream_file(@unparsed_files)
      		{		
      			$html_file=$stream_file;
      			$html_file=~ s/\..*//; 		#stripping off extension
      			$html_file=$html_file.".html";
      			my $status = system("mp2tsa.exe -o $html_file $stream_file");
      		}
      	}
      }
      print "<BR>Scanning Directory: $dir";
      print "<BR>Total Streams Scanned: $count_total";
      print "<BR>Parsed Streams Found : $count_present";
      print "<BR>Unparsed Streams Found: $count_absent";

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        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:

        Code:
        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.

        Comment

        • numberwhun
          Recognized Expert Moderator Specialist
          • May 2007
          • 3467

          #5
          Originally posted by KevinADC
          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:

          Code:
          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

          Comment

          • kanishka1213
            New Member
            • Jul 2009
            • 22

            #6
            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.

            Comment

            • kanishka1213
              New Member
              • Jul 2009
              • 22

              #7
              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_TestStr eams/64QAM_lipsync48 0i.trp'
              Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync48 0i.trp'
              Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync48 0p.trp'
              Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync48 0p.trp'
              Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync72 0p.trp'
              Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync72 0p.trp'
              Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC1080i.TR P'
              Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC1080i.TR P'
              Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC480p.TRP '
              Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC480p.TRP '
              Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC720p.TRP '
              Could not open 'lipsync/Lipsync_TestStr eams/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..t rp'
              Could not open 'Streams/2_k5compress..t rp'
              Could not open 'Streams/2_ref997..trp'
              Could not open 'Streams/2_ref997..trp'
              Could not open 'Streams/acmod1_0..trp'

              Comment

              • numberwhun
                Recognized Expert Moderator Specialist
                • May 2007
                • 3467

                #8
                Originally posted by kanishka1213
                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_TestStr eams/64QAM_lipsync48 0i.trp'
                Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync48 0i.trp'
                Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync48 0p.trp'
                Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync48 0p.trp'
                Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync72 0p.trp'
                Could not open 'lipsync/Lipsync_TestStr eams/64QAM_lipsync72 0p.trp'
                Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC1080i.TR P'
                Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC1080i.TR P'
                Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC480p.TRP '
                Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC480p.TRP '
                Could not open 'lipsync/Lipsync_TestStr eams/LIPSYNC720p.TRP '
                Could not open 'lipsync/Lipsync_TestStr eams/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..t rp'
                Could not open 'Streams/2_k5compress..t rp'
                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

                Comment

                • kanishka1213
                  New Member
                  • Jul 2009
                  • 22

                  #9
                  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\un parsedfile.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

                  Comment

                  • kanishka1213
                    New Member
                    • Jul 2009
                    • 22

                    #10
                    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.

                    Comment

                    Working...