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

Re: [PBML] Find Files in specific Folder but Exclude Subdirectories

Expand Messages
  • vidhut singh
    there is option called $File::Find::prune which if you set in callback function wanted , by using this option you can block the pruned directory .  you can
    Message 1 of 7 , Jul 15, 2009
    • 0 Attachment
      there is option called $File::Find::prune which if you set in callback function 'wanted' , by using this option you can block the pruned directory . 
      you can check  FILE::FIND module in cpan.org, you will get the explaination about wanted and all.  

      ~Vidhut 
      --- On Wed, 15/7/09, hwitche <hwitche@...> wrote:

      From: hwitche <hwitche@...>
      Subject: [PBML] Find Files in specific Folder but Exclude Subdirectories
      To: perl-beginner@yahoogroups.com
      Date: Wednesday, 15 July, 2009, 7:51 PM
























      Hi all,



      How can I stop my find script to go into sub directories and stay in specific directory = "dir2" only?



      $directory=" ..\/dir1\ /dir2";



      @ARGV = ($directory) unless @ARGV;



      ##### BELOW FINDS ALL FILES IN "dir2" AND ALL SUBDIRS



      find(sub {$name{$File: :Find::name} = -f;}, @ARGV);



      ##### QUESTION: How can it be prevented from going into subdir "dir3", "dir4" etc?



      @sorted=sort {lc $a cmp lc $b} keys %name;



      $n=0;

      foreach my $file (@sorted) {

      etc

      }



      Thank you for your help



      Hans


































      Yahoo! recommends that you upgrade to the new and safer Internet Explorer 8. http://downloads.yahoo.com/in/internetexplorer/

      [Non-text portions of this message have been removed]
    • hwitche
      Thank you Vidhut for your help, I would have only one wish left for the perl gurus: to implement a tiny stop tag into the line find(sub {$name{$File:
      Message 2 of 7 , Jul 17, 2009
      • 0 Attachment
        Thank you Vidhut for your help,

        I would have only one wish left for the perl gurus: to implement a tiny "stop" tag into the line "find(sub {$name{$File: :Find::name} = -f;}, @ARGV);". It would be much easier.

        Hans





        --- In perl-beginner@yahoogroups.com, vidhut singh <chat2vidhut@...> wrote:
        >
        > there is option called $File::Find::prune which if you set in callback function 'wanted' , by using this option you can block the pruned directory .�
        > you can check �FILE::FIND module in cpan.org, you will get the explaination about wanted and all. �
        >
        > ~Vidhut�
        > --- On Wed, 15/7/09, hwitche <hwitche@...> wrote:
        >
        > From: hwitche <hwitche@...>
        > Subject: [PBML] Find Files in specific Folder but Exclude Subdirectories
        > To: perl-beginner@yahoogroups.com
        > Date: Wednesday, 15 July, 2009, 7:51 PM
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        > Hi all,
        >
        >
        >
        > How can I stop my find script to go into sub directories and stay in specific directory = "dir2" only?
        >
        >
        >
        > $directory=" ..\/dir1\ /dir2";
        >
        >
        >
        > @ARGV = ($directory) unless @ARGV;
        >
        >
        >
        > ##### BELOW FINDS ALL FILES IN "dir2" AND ALL SUBDIRS
        >
        >
        >
        > find(sub {$name{$File: :Find::name} = -f;}, @ARGV);
        >
        >
        >
        > ##### QUESTION: How can it be prevented from going into subdir "dir3", "dir4" etc?
        >
        >
        >
        > @sorted=sort {lc $a cmp lc $b} keys %name;
        >
        >
        >
        > $n=0;
        >
        > foreach my $file (@sorted) {
        >
        > etc
        >
        > }
        >
        >
        >
        > Thank you for your help
        >
        >
        >
        > Hans
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        >
        > Yahoo! recommends that you upgrade to the new and safer Internet Explorer 8. http://downloads.yahoo.com/in/internetexplorer/
        >
        > [Non-text portions of this message have been removed]
        >
      • merlyn@stonehenge.com
        ... hwitche I would have only one wish left for the perl gurus: to implement a hwitche tiny stop tag into the line find(sub {$name{$File: :Find::name} =
        Message 3 of 7 , Jul 18, 2009
        • 0 Attachment
          >>>>> "hwitche" == hwitche <hwitche@...> writes:

          hwitche> I would have only one wish left for the perl gurus: to implement a
          hwitche> tiny "stop" tag into the line "find(sub {$name{$File: :Find::name} =
          hwitche> -f;}, @ARGV);". It would be much easier.

          Just throw an exception.


          eval {
          find sub {
          ...
          die "##done" if $we_want_to_stop;
          ...
          }, @starting points;
          };
          die $@ if $@ and $@ !~ /##done/;

          --
          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
        • Jon Reynolds
          ... You never fail to let me know just how far away I am from being a perl guru or a beginner, for that matter Randall. But I always get hopeful the more your
          Message 4 of 7 , Jul 21, 2009
          • 0 Attachment
            merlyn@... wrote:

            > Just throw an exception.
            >
            > eval {
            > find sub {
            > ...
            > die "##done" if $we_want_to_ stop;
            > ...
            > }, @starting points;
            > };
            > die $@ if $@ and $@ !~ /##done/;
            >
            You never fail to let me know just how far away I am from being a perl
            guru or a beginner, for that matter Randall. But I always get hopeful
            the more your Greek begins to be readable.

            Jon
          • Hans Witschi
            Hi Randal an Jon, I respectfully insist: I still DREAM of a switch in: find(sub {$name{$File::Find::name} = -f;}, @ARGV); For now I have a construction with
            Message 5 of 7 , Jul 25, 2009
            • 0 Attachment
              Hi Randal an Jon,

              I respectfully insist:

              I still DREAM of a switch in:

              find(sub {$name{$File::Find::name} = -f;}, @ARGV);

              For now I have a construction with "@exclude=("DIR")", which works well. But
              I don't like it...

              ...and I couldn't fall in love with Randal'solution

              eval {
              find sub {
              ...
              die "##done" if $we_want_to_ stop;
              ...
              }, @starting points;
              };
              die $@ if $@ and $@ !~ /##done/;

              because it didn't work.

              However, my point is: it is too complicated and too time consuming to list
              directories for exclusion.

              Why so much coding when it could be achieved much easier, having somewhere
              deeper in the perl machine code a stop switch like "stay" in the
              "$File::Find::name" module:

              find(sub {$name{$File::Find::name} = -f;}, @ARGV stay);

              Unimaginable no one had similar thougts so far on that.

              Hans


              On Tue, Jul 21, 2009 at 3:31 AM, Jon Reynolds <jonr@...> wrote:

              >
              >
              > merlyn@... <merlyn%40stonehenge.com> wrote:
              >
              > > Just throw an exception.
              > >
              > > eval {
              > > find sub {
              > > ...
              > > die "##done" if $we_want_to_ stop;
              > > ...
              > > }, @starting points;
              > > };
              > > die $@ if $@ and $@ !~ /##done/;
              > >
              > You never fail to let me know just how far away I am from being a perl
              > guru or a beginner, for that matter Randall. But I always get hopeful
              > the more your Greek begins to be readable.
              >
              > Jon
              >
              >


              [Non-text portions of this message have been removed]
            • merlyn@stonehenge.com
              ... Hans Why so much coding when it could be achieved much easier, having somewhere Hans deeper in the perl machine code a stop switch like stay in the
              Message 6 of 7 , Jul 26, 2009
              • 0 Attachment
                >>>>> "Hans" == Hans Witschi <hwitche@...> writes:

                Hans> Why so much coding when it could be achieved much easier, having somewhere
                Hans> deeper in the perl machine code a stop switch like "stay" in the
                Hans> "$File::Find::name" module:

                Hans> find(sub {$name{$File::Find::name} = -f;}, @ARGV stay);

                What would "stay" do again? Maybe I missed your original
                problem, because my solution aborts *all* crawling mid-stride, when
                you hit a particular place.

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