469,306 Members | 1,987 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Getting File System Root Directory

I've seen install programs that search a hard drive for previous instances
of a program, or to find installs of other needed programs.

I need to search a hard drive for any installations of OpenOffice. I know
in *nix I can start by using "/" as the file name and doing a recursive
listing of the file system from there. (Yes -- I know about permissions to
read directories -- that's another issue I've already solved.)

How do I find the root level for Windows boxen? For example, if a Windows
box has C:, D:, and E: drives, how do I get a list of all the drives so I
can scan them -- AND how can I tell which ones have media in them so I
don't scan floppies or CD-ROMs that are empty?

Thanks!

Hal
Jul 17 '05 #1
3 19080
For finding the drives on windows box,
do you need to be machine independent or
are you willing to use JNI?

There is a windows function that returns a long
with one bit for each of the possible 26 drives A thru Z.

I have a JNI program that uses it to find out how
much disk space there is on my C: and D: drives that
I can send you as an example.

By convention, A and B are floppy, beyond that I don't
know how to tell if a drive is a CD-ROM, tape, or
mapped network drive. There may be more MS library
functions that do that though.

Phil...

"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:asjeb.642760$o%2.301439@sccrnsc02...
I've seen install programs that search a hard drive for previous instances
of a program, or to find installs of other needed programs.

I need to search a hard drive for any installations of OpenOffice. I know
in *nix I can start by using "/" as the file name and doing a recursive
listing of the file system from there. (Yes -- I know about permissions to read directories -- that's another issue I've already solved.)

How do I find the root level for Windows boxen? For example, if a Windows
box has C:, D:, and E: drives, how do I get a list of all the drives so I
can scan them -- AND how can I tell which ones have media in them so I
don't scan floppies or CD-ROMs that are empty?

Thanks!

Hal

Jul 17 '05 #2
Phil... wrote:
For finding the drives on windows box,
do you need to be machine independent or
are you willing to use JNI?
I'm trying to keep it platform independent. At this point I'm making sure
it works on Linux and Windows. I want to test Mac in a month or two. (I
hear about all I need to worry about is a different file separator
character, which shouldn't be a problem since I get that from either the
System properties or the File class.)

Although I am adding in code to handle a few things that might differ from
system to system.
There is a windows function that returns a long
with one bit for each of the possible 26 drives A thru Z.

I have a JNI program that uses it to find out how
much disk space there is on my C: and D: drives that
I can send you as an example.

By convention, A and B are floppy, beyond that I don't
know how to tell if a drive is a CD-ROM, tape, or
mapped network drive. There may be more MS library
functions that do that though.

Phil...
I found one way to do it -- if I detect I'm on Windows, I can cycle through
the entire list of strings ("A:", "B:", etc) and check if each exists.
It's a small detail, but I was hoping there was an "elegant" cross-platform
way to specify the root directory (like "/" in *nix). I even looked
through Swing to see if there was anything in JFileChooser that would let
me make a filechooser and get the info, without ever showing the chooser.

Thanks, again, Phil, for the info!

Hal
"Hal Vaughan" <ha*@thresholddigital.com> wrote in message
news:asjeb.642760$o%2.301439@sccrnsc02...
I've seen install programs that search a hard drive for previous
instances of a program, or to find installs of other needed programs.

I need to search a hard drive for any installations of OpenOffice. I
know in *nix I can start by using "/" as the file name and doing a
recursive
listing of the file system from there. (Yes -- I know about permissions

to
read directories -- that's another issue I've already solved.)

How do I find the root level for Windows boxen? For example, if a
Windows box has C:, D:, and E: drives, how do I get a list of all the
drives so I can scan them -- AND how can I tell which ones have media in
them so I don't scan floppies or CD-ROMs that are empty?

Thanks!

Hal


Jul 17 '05 #3
File[] roots = File.listRoots();
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Mr. B | last post: by
reply views Thread by Bill Burwell | last post: by
13 posts views Thread by raykyoto | last post: by
1 post views Thread by BW | last post: by
5 posts views Thread by Justin Fancy | last post: by
13 posts views Thread by lawpoop | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.