🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #12391

Re: Disk Drives object

#12391
From: Julian Monypenny
Date: Thu, 07 Jan 1999 00:00
54 lines
2121 bytes
Mark,

I use the following code to list Windows NT drives. Note, the list only
includes hard drives, not floppy or CD drives. You could assume the A drive
exists, but if you try to access it when it doesn't contain a disk you get a
Windows dialog message. The default assignment of the root directory in
ListDrives is designed to work with non-Windows systems.

 public static final String separator = File.separator;

 /**
  * Lists the drives on the system.
  * @return  an array of the drives on the system
  */
 public static final String[] listDrives() {
  Vector list = new Vector();
  for (char drive = 'C'; drive < 'Z'; drive++) {
   if (isDirectory(String.valueOf(drive) + ":")) {
    list.addElement(String.valueOf(drive) + ":");
   }
  }
  if (list.isEmpty()) {
   list.addElement(separator);
  }
  String drives[] = new String[list.size()];
  list.copyInto(drives);
  return drives;
 }

 /**
  * Checks if a string contains the name of a directory.
  * @param name  the string that contains the name
  * @return  true if the name is a directory; false otherwise
  */
 public static final boolean isDirectory(String name) {
  File file = new File(name + separator);
  return (file.isDirectory() &&
   file.exists() &&
   !name.equals(""));
 }

Julian

Mark Tiede wrote in message <36940D10.C3A4EFBD@ibm.net>...
>All,
>
>   I just spent about 3 hours looking through docs and source trying to
>find out how I could make an object like the filedialog component does.
>I want to make a list box that has the list of disk drives in it.
>
>   Any ideas?
>
>   Thanks.
>
Technical Details
Message-ID: <773205$fm114@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36940D10.C3A4EFBD@ibm.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,c87bf8c8df7752dc
X-Google-Attributes: gid111d45,public
From: "Julian Monypenny" <jmonypenny@news400.com>
Subject: Re: Disk Drives object
Date: 1999/01/07
Message-ID: <773205$fm114@forums.borland.com>
X-Deja-AN: 429903227
References: <36940D10.C3A4EFBD@ibm.net>
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing