-5

Please give any suggestion or snippet or anything that may work.

I have already tried wanted function but how do I exclude some directory while recursing?

Jens
  • 69,818
  • 15
  • 125
  • 179
Baabla
  • 1
  • 2
    If you already have code you've tried, please edit your question and paste it in. That way we can see that you've made an effort, and guide you to a solution (as opposed to writing the code for you in its entirety). – stevieb Dec 21 '16 at 16:03
  • [Look into this](http://stackoverflow.com/questions/36822986/print-files-and-subdirectories-of-given-directory/36823076#36823076) and Please Include something to show efforts, You can't just ask us to write code here. – AbhiNickz Dec 21 '16 at 16:18

1 Answers1

1

In Linux, you can make use of the Linux "find" and "grep" commands and run those Linux commands in Perl using qx to store Linux command result in Perl.

e.g.

$cmd = "find . | grep -v 'dir1\|dir2\|...\|dirn'";
$result=qx($cmd);

The above command combinations do the following:

  1. The find command will list the all the directory and files recursively.
  2. The pipe "|" will pass the find result to grep command
  3. The grep -v command will print on screen only the string not exist in the "dir1", "dir2"..."dirn" to be ignored
  4. At last, the qx command will execute the find and grep Linux commands and stored the output to $result variable.

You can do the similar thing in Windows. The only difference is to use the Windows command line.

e.g.

$result=qx('dir /b/s | find /v "workspace" | find /v "TVM"')

The above command will list all the directory recursively except the directory has name "workspace" or "TVM".

csay
  • 31
  • 3
  • 2
    csay, welcome to SO! We highly appreciate that you spent effort to help because that's the whole purpose of this site. Your code would work (as far as I can see), but the OP asked for a Perl solution. (Actually he asked us to write the code for him, which is not very well received here.) Your post is well written, properly formatted and explains your solution. I like that – and I wished the OP had the same attitude! – PerlDuck Dec 21 '16 at 21:33