aspose file tools
The moose likes Beginning Java and the fly likes I want to print on which level the file is present in given directory structure when using recursion Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "I want to print on which level the file is present in given directory structure when using recursion" Watch "I want to print on which level the file is present in given directory structure when using recursion" New topic
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
    
  66

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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I want to print on which level the file is present in given directory structure when using recursion
 
Similar Threads
Meyer's Java Prog study guide pg 381 ...
File question from JQPlus
How do I package stuff?
listing files in a jar file
Recursive file search and still filtering file and directory names?