CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    JComboBox and System Drive INFo

    Hi all,
    I would like to add my system drives(exa:- C:,D:,E: and mapped network drives ) to a combobox.SO , which method i should use to add all these at runtime.see,my network drives may change dynamically.so i need to add all these drives at run time only.this question is just like the "Look in:" item available in windows start menu -> find -> files & folders tabpage 1.


    Thanks & Regards
    Panda
    EXIMSoft
    Bangalore
    rp_panda@blr.reliancesystems.com



  2. #2
    Join Date
    Jan 2000
    Location
    CA, USA
    Posts
    305

    Re: JComboBox and System Drive INFo

    Hi,
    The following should give you the system drives.

    File[] roots = FileSystemView.getFileSystemView().getRoots();
    for (int i = 0; i < roots.length; i++)
    {
    comboBoxinstance.addItem(roots[i]);
    }

    Good Luck.
    Kannan



  3. #3
    Join Date
    Mar 2003
    Location
    Lahore, Pakistan
    Posts
    38
    Can we differenciate between network drive (Mapped drive) and local drive (Hard Disk Drive)? You provide code for listing of all drives, but how about identification of both ?
    Anyone who has never made a mistake has never tried anything new.

  4. #4
    Join Date
    Oct 2006
    Posts
    229

    Re: JComboBox and System Drive INFo

    try this


    Code:
       DriveInfo[] driveList = DriveInfo.GetDrives();
    
       // Loop through the list of drives
    
       foreach (DriveInfo drive in driveList)
    
       {
    
          // It's a HDD
    
          if (drive.DriveType == DriveType.Fixed)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 3);
    
          }
    
          // It's a CD-ROM, DVD-ROM, CD-RW, DVD+-RW or any other similar drive
    
          else if (drive.DriveType == DriveType.CDRom)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 0);
    
          }
    
          // It's a floppy drive
    
          else if (drive.DriveType == DriveType.Removable)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 2);
    
          }
    
          // It's a network drive
    
          else if (drive.DriveType == DriveType.Network)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 4);
    
          }
    
          // It's a RAM drive
    
          else if (drive.DriveType == DriveType.Ram)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 6);
    
          }

  5. #5
    Join Date
    Dec 2005
    Posts
    251

    Re: JComboBox and System Drive INFo

    Quote Originally Posted by 2MuchRiceMakesMeSick
    try this


    Code:
       DriveInfo[] driveList = DriveInfo.GetDrives();
    
       // Loop through the list of drives
    
       foreach (DriveInfo drive in driveList)
    
       {
    
          // It's a HDD
    
          if (drive.DriveType == DriveType.Fixed)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 3);
    
          }
    
          // It's a CD-ROM, DVD-ROM, CD-RW, DVD+-RW or any other similar drive
    
          else if (drive.DriveType == DriveType.CDRom)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 0);
    
          }
    
          // It's a floppy drive
    
          else if (drive.DriveType == DriveType.Removable)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 2);
    
          }
    
          // It's a network drive
    
          else if (drive.DriveType == DriveType.Network)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 4);
    
          }
    
          // It's a RAM drive
    
          else if (drive.DriveType == DriveType.Ram)
    
          {
    
             treeDrives.Nodes.Add(drive.ToString(), drive.ToString(), 6);
    
          }
    Not only was the question you answered 4 years old, the answer was not even in Java.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured