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

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

Expand Messages
  • Kenneth Wolcott
    ... 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
    Message 1 of 10 , May 31, 2010
    • 0 Attachment
      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]
    • gopi chand
      Thanks a lot Kenneth.It worked.BTW where to get the find2perl tool ... From: Kenneth Wolcott Subject: Re: [PBML] Script to print all
      Message 2 of 10 , Jun 1, 2010
      • 0 Attachment
        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]
      • merlyn@stonehenge.com
        ... gopi Thanks a lot Kenneth.It worked.BTW where to get the find2perl tool Same directory as Perl is in. Probably /usr/bin or /usr/local/bin. If Perl is in
        Message 3 of 10 , Jun 1, 2010
        • 0 Attachment
          >>>>> "gopi" == gopi chand <gopichand84@...> writes:

          gopi> Thanks a lot Kenneth.It worked.BTW where to get the find2perl tool

          Same directory as Perl is in. Probably /usr/bin or /usr/local/bin.

          If Perl is in your path, so should find2perl be.

          --
          Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
          <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
          Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
          See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
        Your message has been successfully submitted and would be delivered to recipients shortly.