Getting File System Root Directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hal Vaughan

    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
  • Phil...

    #2
    Re: Getting File System Root Directory

    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" <hal@thresholdd igital.com> wrote in message
    news:asjeb.6427 60$o%2.301439@s ccrnsc02...[color=blue]
    > 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[/color]
    to[color=blue]
    > 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[/color]


    Comment

    • Hal Vaughan

      #3
      Re: Getting File System Root Directory

      Phil... wrote:
      [color=blue]
      > For finding the drives on windows box,
      > do you need to be machine independent or
      > are you willing to use JNI?[/color]

      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.
      [color=blue]
      > 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...[/color]

      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
      [color=blue]
      > "Hal Vaughan" <hal@thresholdd igital.com> wrote in message
      > news:asjeb.6427 60$o%2.301439@s ccrnsc02...[color=green]
      >> 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[/color]
      > to[color=green]
      >> 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[/color][/color]

      Comment

      • Dale Mitchell

        #4
        Re: Getting File System Root Directory

        File[] roots = File.listRoots( );

        Comment

        Working...