in reply to Re: To retrieve all files according to given path list
in thread To retrieve all files according to given path list

Not quite. While it's a step in the right direction, your program dies on inputs (2) and (4), and returns the incorrect result for inputs (1) and (3). The OP's tool has a very odd usage syntax.

devlele, have you considered using a switch (say -r) to decide whether to recurse or not. * normally means something else.

Replies are listed 'Best First'.
Re^3: To retrieve all files according to given path list
by blazar (Canon) on Dec 22, 2005 at 16:56 UTC
    Not quite. While it's a step in the right direction, your program dies on inputs (2) and (4), and returns the incorrect result for inputs (1) and (3). The OP's tool has a very odd usage syntax.
    Oh, that was just for illustrational purposes. Of course it would be up to him to decide to which depth level to recurse based upon actual input. Indeed the requirements are quite strange...


      Hi, I am a newbee to PERL, so can you please explain me what this tool is doing with what are the parameters ? I have actually tried this with c:\directoryname but it gives everything in that directory as well as in subdirectories. Is there any way to mention depth ? What I mean is, if I give c:\temp, it should only show me the directories and files in that directory and not under the its subdirectories.

      Please help.
      Thanks.
        Hi, I am a newbee to PERL

        Indeed! In fact, s/PERL/(qw|P p|)[rand 2].'erl'/ge - but not "PERL". And I also think s/(?<=newb)ee/ie/g - but I'm not a native English speaker...

        so can you please explain me what this tool is doing with what are the parameters

        The docs will explain it to you far better than I ever could. I didn't use anything exotic so that should be straightforward. If you encounter any specific difficulty, then do not exitate to ask for further clarifications.

        I have actually tried this with c:\directoryname but it gives everything in that directory as well as in subdirectories.

        Indeed this was noted by ikegami here. Incidentally this is my response to him.

        Is there any way to mention depth

        You can:

        • hold a $depth variable yourself, $depth++ at "preprocess" time, $depth-- at "postprocess" time and prune (i.e. use $File::Find::prune) accordingly;
        • use one of the other modules suggested by me and by others, that build upon File::Find; e.g.: File::Find::Rule - a quick glance at the latter revealed that it provides support for depth control.
        What I mean is, if I give c:\temp, it should only show me the directories and files in that directory and not under the its subdirectories.

        As also noted by ikegami in the same post as above, your UI syntax is somewhat odd. But if you really want to go with that, then just do something along the lines of the following:

        die "Too bad!\n" unless @ARGV; for (shift) { if (/\*$/) { find { ... }, glob; } else { die "`$_': not a directory!\n" unless -d; my @files=glob "$_/*"; # ... } }

        Here I used glob because I find it to be appropriate in most cases, YMMV may vary of course, and like many others you may prefer to opendir and readdir instead.

        Also notice that I used a for loop for the sole purpose of aliasing $_, which is a practice that many people don't like. But I do, so bear with me! I may have used local $_=shift instead.