Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I want to print on which level the file is present in given directory structure when using recursion  RSS feed

 
Chaitanya Tedla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
author & internet detective
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Chaitanya Tedla
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help!!
I got that!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!