I know how to find a directory if I know the full path name of the directory I'm searching for..But, let's say I only know the directory name, and not the full path name..How can I find that directory on a users system? Is there some recursive function or looping structure to achieve this?

Recommended Answers

All 3 Replies

Ok, I found out how to search. Now the only thing I need to know is, how do you find out what the users root directory is?

This is what I'm trying right now, but it's not working..

public File PathStart()
   {
	for (char dirs='A'; dirs >= 'Z'; dirs++)
	{
		File path = new File(dirs + "://");
			if (path.isDirectory())
			{
				startingPath = path;
				System.out.println(startingPath.toString());
			}
	}
	return startingPath;
   }

For one that will only work on Windows machines, not anywhere else.
Try to write Java code to be platform independent...

Look at the class System for a method getProperties().
This will retrieve the system properties which, among other things, contains a reference to the current working directory as well as to the current user's home directory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.