Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

help improve this code without the use of HashMap

 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Winston
I will check that out. Thanks for your availability.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Winston
Your hint led me to this:
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Ngom wrote:Your hint led me to this:


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 that trawl() 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.

HIH

Winston
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


For simplicity and speed, I would hazard that Files.walkFileTree is going to give you some decent performance.



Hi Dieter,
Could you please post a simple code about how this could be achieved? Thanks in advance.
 
Run away! Run away! Here, take this tiny ad with you:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic