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

Thread: hard disk Space

  1. #1
    Join Date
    Jun 2002
    Posts
    34

    hard disk Space

    Can anyone pls tell me how to find out all the hard disk installed in the PC

    ( c:, d: , e

    and how to find their sizess....

    Pls Help me out
    thank u

  2. #2
    Join Date
    Aug 2002
    Location
    Washington, USA
    Posts
    104
    Look at the Scripting.FileSystemObject object. Specifically, the Drives collection thereof.
    - Shawn
    MCP, VB6: Desktop Apps
    [ C# | VB | .NET | Java | VC++ | Perl | PHP | Javascript ]
    Unless otherwise stated, all sample code provided is UNTESTED.
    http://www.codemastershawn.com

  3. #3
    Join Date
    Sep 2000
    Posts
    77
    I guess Scripting.FileSystemObject may solve your problem, additionally you may have depecdency of Microsoft Scripting runtime.

    This can be avioded by using API

    GetLogicalDrives

    The above API involves quite a bit coding as you need to resolve the drives by your self. If you are not very particular about the dependency issue, you may use Scripting.FileSystemObject as suggested by the other gentleman, ShawnDev.


    Hope this helps.

    -kiran.

  4. #4
    Join Date
    May 2002
    Location
    Colombo,Sri Lanka
    Posts
    1,110
    Dim oFSO As Object

    Set oFSO = CreateObject("Scripting.FileSystemObject")


    lblDiskSpace = With oFSO.Drives(lstDrives).AvailableSpace / 1024 & " K"

  5. #5
    Join Date
    Jun 2002
    Posts
    34
    how to know all the drives in the system...

  6. #6
    Join Date
    Sep 2001
    Location
    Québec, Canada
    Posts
    1,923
    Code:
        Dim fso As New FileSystemObject
        Dim objDrive As Drive
        
        For Each objDrive In fso.Drives
            MsgBox objDrive.DriveLetter
        Next
    JeffB
    CodeGuru VB FAQ Visual Basic Frequently Asked Questions
    VB Code color Tool to color your VB code on CodeGuru
    Before you post Importants informations to know before posting

  7. #7
    Join Date
    Jun 2002
    Posts
    34
    hi JeffB

    when i write the above code and run it say filesystemobject not declared

    in help MSDN it is using as scription language
    what should i Do

    Pls help me

    Thank U

  8. #8
    Join Date
    Jun 2002
    Posts
    34
    hi JeffB

    when i write the above code and run it say filesystemobject not declared

    in help MSDN it is using as scription language
    what should i Do

    Pls help me

    Thank U

  9. #9
    Join Date
    Feb 2002
    Location
    Chennai, India
    Posts
    45
    Make sure that you have referenced Microsoft Scripting Runtime
    under project / references option.

  10. #10
    Join Date
    Apr 2002
    Posts
    174
    You can use this api to get many information about yuor disks:

    <From allapi guide>

    1) Declare Function GetLogicalDrives Lib "kernel32" Alias "GetLogicalDrives" () As Long

    If the function succeeds, the return value is a bitmask representing the currently available disk drives. Bit position 0 (the least-significant bit) is drive A, bit position 1 is drive B, bit position 2 is drive C, and so on.

    2) Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

    The return value specifies the type of drive. It can be one of the following values:
    DRIVE_UNKNOWN
    The drive type cannot be determined.

    DRIVE_NO_ROOT_DIR
    The root directory does not exist.

    DRIVE_REMOVABLE
    The disk can be removed from the drive.

    DRIVE_FIXED
    The disk cannot be removed from the drive.

    DRIVE_REMOTE
    The drive is a remote (network) drive.

    DRIVE_CDROM
    The drive is a CD-ROM drive.

    DRIVE_RAMDISK
    The drive is a RAM disk.

    3)Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long

    · lpRootPathName
    Points to a null-terminated string that specifies the root directory of the disk to return information about. If lpRootPathName is NULL, the function uses the root of the current directory.

    · lpSectorsPerCluster
    Points to a variable for the number of sectors per cluster.

    · lpBytesPerSector
    Points to a variable for the number of bytes per sector.

    · lpNumberOfFreeClusters
    Points to a variable for the total number of free clusters on the disk.

    · lpTotalNumberOfClusters
    Points to a variable for the total number of clusters on the disk.

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