<p>For a project I'm working on. I need to look for an executable on the filesystem. For UNIX derivatives, I assume the user has the file in the mighty $PATH variable, but there is no such thing on Windows.</p>

<p>I can safely assume the file is at most 2 levels deep into the filesystem, but I don't know on what drive it will be. I have to try all drives, but I can't figure out how to list all available drives (which have a letter assigned to it).</p>

<p>Any help?</p>

<p><strong>EDIT:</strong> I know there is a %PATH% variable, but it is not as integrated as in UNIX systems. For instance, the application I'm looking for is OpenOffice. Such software would not be in %PATH%, typically.</p>

[{'answer_id': 51327, 'author': 'Frank Krueger', 'author_id': 338, 'author_profile': 'https://Stackoverflow.com/users/338', 'pm_score': -1, 'selected': False, 'text': '<p>Of course there is a <code>PATH</code> environment variable <a href="http://en.wikipedia.org/wiki/Environment_variable#System_path_variables" rel="nofollow noreferrer">in Windows</a>.</p>\n\n<blockquote>\n  <blockquote>\n    <p><code>%PATH%</code>\n    This variable contains a semicolon-delimited list of directories in which the command interpreter will search for executable files. Equivalent to the UNIX $PATH variable.</p>\n  </blockquote>\n</blockquote>\n'}, {'answer_id': 51330, 'author': 'Greg Hewgill', 'author_id': 893, 'author_profile': 'https://Stackoverflow.com/users/893', 'pm_score': 0, 'selected': False, 'text': '<p>Windows does indeed have a PATH environment variable. It has a different syntax from the Unix one because it uses semicolon (;) as a separator instead of colon (:) and you have to watch for quoted strings that might contain spaces. But, it\'s there.</p>\n\n<p>If this other program\'s installer adds its own directory to the PATH environment variable, then you could rely on that. However, as you mention, Windows installers typically do not need to add the application path to the PATH because they install a start menu shortcut or something else instead.</p>\n\n<p>For drive letters in Java, one approach would be to try them all, there are only going to be at most 24 (C through Z) that are of any use. Or, you could shell out and run "net use" and parse the results, though that is a bit messier.</p>\n'}, {'answer_id': 51331, 'author': 'Tony BenBrahim', 'author_id': 80075, 'author_profile': 'https://Stackoverflow.com/users/80075', 'pm_score': 6, 'selected': True, 'text': '<p><a href="http://docs.oracle.com/javase/7/docs/api/java/io/File.html#listRoots()" rel="noreferrer">http://docs.oracle.com/javase/7/docs/api/java/io/File.html#listRoots()</a></p>\n\n<pre><code>File[] roots = File.listRoots();\nfor(int i = 0; i &lt; roots.length ; i++)\n    System.out.println("Root["+i+"]:" + roots[i]);\n</code></pre>\n\n<p>google: list drives java, first hit:-)</p>\n'}, {'answer_id': 255980, 'author': 'myplacedk', 'author_id': 28683, 'author_profile': 'https://Stackoverflow.com/users/28683', 'pm_score': 2, 'selected': False, 'text': '<p>Looking "everywhere" can be very messy.</p>\n\n<p>Look at a CD-rom drive, and it spins up. That can be very noisy.</p>\n\n<p>Look at a network drive, and it may be very slow. Maybe the server is down, and you may need to wait for minutes until it times out.</p>\n\n<p>Maybe (for Windows-machines) you should just look in the start-menu. If nothing there points at OOo, it\'s probably not installed. If it is, the user is probably an advanced user, that will have no problems pointing out the location manually.</p>\n'}, {'answer_id': 2092379, 'author': 'Defd', 'author_id': 250777, 'author_profile': 'https://Stackoverflow.com/users/250777', 'pm_score': -1, 'selected': False, 'text': '<p>Use JNI.\nThis is perfect for c++ code. \nNot only you can list all drives but also get the corresponding drive type (removable,local disk, or cd-rom,dvd-rom...etc)</p>\n'}]
['https://Stackoverflow.com/questions/51320', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2018/']