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



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.
  • Comment on Re^4: To retrieve all files according to given path list

Replies are listed 'Best First'.
Re^5: To retrieve all files according to given path list
by blazar (Canon) on Dec 23, 2005 at 11:14 UTC
    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.