-3

I don't have much knowledge on file operations, and I'm trying to solve this problem. I have a folder called 'NaTel' which is present in another folder on D: drive.

So, I want the location path of this directory as D:\Teamwork\ in output(that is where it is present). I've been seeing various examples but how can I do this with or without recursion ?

2
  • 2
    Also, please clarify your question ,what do you mean "I want the location path of this directory as 'D:\Teamwork\' in output(that is where it is present)" Commented Sep 11, 2014 at 9:27
  • The program in this link stackoverflow.com/questions/15624226/… Commented Sep 11, 2014 at 9:32

1 Answer 1

1

Look this answer given by : Visal K, it have code what you want.

 public void findFile(String name,File file) { File[] list = file.listFiles(); if(list!=null) for (File fil : list) { if (fil.isDirectory()) { findFile(name,fil); } else if (name.equalsIgnoreCase(fil.getName())) { System.out.println(fil.getParentFile()); } } } public static void main(String[] args) { File ff = new File("D:\\"); ff.findFile("NaTel",ff); } 
Sign up to request clarification or add additional context in comments.

2 Comments

That code was not working, it was going into an infinite loop
try by giving : File ff = new File("D:\\Teamwork");, just for check that is it working or not.. it can be also possible that your drive has so much data so it can take long time to scan whole drive.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.