OK, well Path has a toFile() method, and File has a toPath() method, so you can easily convert between the two. I think I've given you enough to get to your own solution. The important thing is to understand how thattrawl()method works; don't just parrot the code. Otherwise, you'll be back as soon as you need to do something slightly different.
So, if you haven't already, get out a pencil and paper and write down what it does with a few sample file names. You don't need to be exhaustive, but do a few levels, so that you understand what's going on.
Unless you come from a pure maths background, recursion can be very difficult to "visualise". As I said previously, I've been at this lark a long time, and I still have to think hard about it.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Joined: May 08, 2014
Now that i have two working programs, i will have to choose one. The code i posted first runs pretty faster if i remove the file i/o.
Anybody else who could share with us another way to achieve this. I mean listing all sub folders of a given directory no matter their level in the tree structure.
You can always create a new File object from the current File's Canonical Path, then a new File object from the current File's Absolute Path, and then check if they are equal. Suspect NTFS is not gonna play nice with that though.
For simplicity and speed, I would hazard that Files.walkFileTree is going to give you some decent performance. Depending on how lightweight your visitor is.