-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 ?

user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62
Karthik
  • 45
  • 1
  • 8
  • 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)" – JaskeyLam Sep 11 '14 at 09:27
  • The program in this link http://stackoverflow.com/questions/15624226/java-search-for-files-in-a-directory – Karthik Sep 11 '14 at 09:32

1 Answers1

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);
    }
Community
  • 1
  • 1
user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62
  • That code was not working, it was going into an infinite loop – Karthik Sep 11 '14 at 09:36
  • 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. – user3145373 ツ Sep 11 '14 at 09:39