6 Replies - 293 Views - Last Post: 30 May 2019 - 07:35 AM Rate Topic: -----

#1 overwhelmed_student   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 10-May 18

Path getChild()

Posted 30 May 2019 - 05:52 AM

Hi,

I want to write a program that prints me every path from the given root and I am having a little trouble with it. While path has the method getParent(), I want to go down instead of up until I reach the end. I thought a binary search tree traversal would be exactly what I need to get every path. Here is my code:
    public static void getEveryDirectory(Path path) {
        if(path != null) {
            list(path.subpath(1, path.getNameCount()+1));
        }
        System.out.println(path.toString());
    }


However, I can't seem to access the "child" node. Let's say I have the directory: ParentFile->ChildFile. My Path is ParentFile. How do I access ChildFile now? (I want to do it with Path since this is a "new" addition and I want to get familiar with the limitations of it.)

Is This A Good Question/Topic? 0
  • +

Replies To: Path getChild()

#2 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: Path getChild()

Posted 30 May 2019 - 06:07 AM

I don't see any methods in Path that return the contents of the folder that Path points to.
Was This Post Helpful? 0
  • +
  • -

#3 overwhelmed_student   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 10-May 18

Re: Path getChild()

Posted 30 May 2019 - 06:19 AM

View PostNormR, on 30 May 2019 - 06:07 AM, said:

I don't see any methods in Path that return the contents of the folder that Path points to.

What do you mean with contents of folder? I only want the names. Or do you mean the files as content of the folder?
Was This Post Helpful? 0
  • +
  • -

#4 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: Path getChild()

Posted 30 May 2019 - 06:35 AM

I mean the contents of a folder to be a list of the files and directories that it contains.

Look at using one of the methods in the Files class.

This post has been edited by NormR: 30 May 2019 - 06:43 AM

Was This Post Helpful? 0
  • +
  • -

#5 overwhelmed_student   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 71
  • Joined: 10-May 18

Re: Path getChild()

Posted 30 May 2019 - 06:44 AM

View PostNormR, on 30 May 2019 - 06:35 AM, said:

I mean the contents of a folder to be a list of the files and directories that it contains.

Look at using one of the methods in the Files class.


Oh, so there really is no way of accessing the content? Okay, I'll give it a try with Files then.
Was This Post Helpful? 0
  • +
  • -

#6 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 780
  • View blog
  • Posts: 5,842
  • Joined: 25-December 13

Re: Path getChild()

Posted 30 May 2019 - 06:48 AM

Quote

there really is no way of accessing the content?

I didn't see any. Maybe someone else will tell us if there is.
Was This Post Helpful? 0
  • +
  • -

#7 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3638
  • View blog
  • Posts: 16,706
  • Joined: 20-September 08

Re: Path getChild()

Posted 30 May 2019 - 07:35 AM

https://docs.oracle....al/io/walk.html
is what you want. Removing just a little code will get you exactly what you want
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1