Search code examples
vb6system.io.filefilesysteminfo

In VB6, how to access FileSystem.GetFileInfo()?


Throwback on an old project and needing to use VB6. I'm having an issue in referencing the appropriate DLL that contains System.IO in the old VB6 IDE.

I have tried to reference: C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll - error: Can't add reference to specified file

Added a reference to C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.tlb - doesn't work.

Added reference to C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.tlb - there is no System.IO from the intellisense.

enter image description here

Can someone please post the step-by-step instructions?


Solution

  • Got this somewhat working with:

    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
    
    Dim info As DiskInformation
    Dim lAnswer As Long
    Dim lpRootPathName As String
    Dim lpSectorsPerCluster As Long
    Dim lpBytesPerSector As Long
    Dim lpNumberOfFreeClusters As Long
    Dim lpTotalNumberOfClusters As Long
    Dim lBytesPerCluster As Long
    Dim lNumFreeBytes As Double
    Dim dPercentFreeClusters As Double
    Dim sString As String
    
    lpRootPathName = "c:\"
    lAnswer = GetDiskFreeSpace(lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters)
    lBytesPerCluster = lpSectorsPerCluster * lpBytesPerSector
    
    ' Throws overflow exception - I guess there were no Terabyte drives when VB6 came around
    ' lNumFreeBytes = lBytesPerCluster * lpNumberOfFreeClusters
    
    'sString = "Number of Free Bytes : " & lNumFreeBytes & vbCr & vbLf
    'sString = sString & "Number of Free Kilobytes: " & (lNumFreeBytes / 1024) & "K" & vbCr & vbLf
    'sString = sString & "Number of Free Megabytes: " & Format(((lNumFreeBytes / 1024) / 1024), "0.00") & "MB"
    
    dPercentFreeClusters = Round(lpNumberOfFreeClusters / lpTotalNumberOfClusters * 100, 2)
    

    There is, however, an Overflow exception being thrown when trying to calculate the number of free bytes.

    I would like to get this working with My.Computer.FileSystem. Suggestions?