| Author |
I want to print on which level the file is present in given directory structure when using recursion
|
Chaitanya Tedla
Greenhorn
Joined: May 15, 2011
Posts: 3
|
|
Hi,
I want to print on which level file is present in a given root directory A:
for example::
A is my root directory..
I have subdirectories B and C in that..
And again in B i have D and E directories...
In D,i have files f1,f2
In E,i have files f3,f4..
In C also assume i have some directories..
Now i want to print for each file in which level that is present given a root directory...
Can anyone help me..
My program::
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26183
|
|
Chaitanya,
Welcome to CodeRanch! I added code tags to make your post easier to read. You are pretty close using recursion. Think about the method signature - public void listFilesInDirectory(File dir) .
Suppose it had an extra parameter to keep track of the level. What would you pass in the first time you call it? What would you do to that value when you were one more level down?
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Chaitanya Tedla
Greenhorn
Joined: May 15, 2011
Posts: 3
|
|
Thanks for the help!!
I got that!!
|
 |
 |
|
|
subject: I want to print on which level the file is present in given directory structure when using recursion
|
|
|