Loading ...
Sorry, an error occurred while loading the content.

26914Re: [PBML] Script to print all the files with .zip extentsion in a given directory

Expand Messages
  • gopi chand
    Jun 1, 2010
      Thanks a lot Kenneth.It worked.BTW where to get the find2perl tool



      --- On Mon, 5/31/10, Kenneth Wolcott <kennethwolcott@...> wrote:

      From: Kenneth Wolcott <kennethwolcott@...>
      Subject: Re: [PBML] Script to print all the files with .zip extentsion in a given directory
      To: perl-beginner@yahoogroups.com
      Date: Monday, May 31, 2010, 5:53 PM







       









      On Sat, May 29, 2010 at 22:23, gopi chand <gopichand84@...> wrote:



      >

      >

      > Hi Kenneth

      >

      > This script looks a little bit better,when I run the below script the

      > output is below.Can you help getting rid of this erro?

      >

      > OUTPUT:main::recurse() called too early to check prototype at greep.plline 20.

      > Use of uninitialized value in pattern match (m//) at greep.pl line 9./

      >

      > #!/usr/bin/perl -w

      >

      > use strict;

      >

      > sub recurse($) {

      > my($path) = @_;

      >

      > ## append a trailing / if it's not there

      > $path .= '/' if($path !~ /\/$/);

      >

      > ## print the directory being searched

      > print $path,"\n";

      >

      > ## loop through the files contained in the directory

      > for my $eachFile (glob($path.'*.zip')) {

      >

      > ## if the file is a directory

      > if( -d $eachFile) {

      > ## pass the directory to the routine ( recursion )

      > recurse($eachFile);

      > } else {

      >

      > ## print the file ... tabbed for readability

      > print "\t",$eachFile,"\n";

      > }

      > }

      > }

      >

      > ## initial call ... $ARGV[0] is the first command line argument

      > recurse($ARGV[0]);

      >



      I see that you have chosen a different script :-)



      Here's my advice:



      There's a very old provided tool with perl called "find2perl".



      My understanding of the original problem you wish to solve is solved by

      "find <dir> -name \*.zip".



      So, using "find2perl" with aforementioned find command results in this:



      find2perl . -name \*.zip

      #! /usr/bin/perl -w

      eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'

      if 0; #$running_under_some_shell



      use strict;

      use File::Find ();



      # Set the variable $File::Find::dont_use_nlink if you're using AFS,

      # since AFS cheats.



      # for the convenience of &wanted calls, including -eval statements:

      use vars qw/*name *dir *prune/;

      *name = *File::Find::name;

      *dir = *File::Find::dir;

      *prune = *File::Find::prune;



      sub wanted;



      # Traverse desired filesystems

      File::Find::find({wanted => \&wanted}, '.');

      exit;



      sub wanted {

      /^.*\.zip\z/s

      && print("$name\n");

      }



      What do you think of this?



      Ken



      [Non-text portions of this message have been removed]

























      [Non-text portions of this message have been removed]
    • Show all 10 messages in this topic