W
Wolfgang Kaml
Dear all,
I am using the following code to retrieve the size of a certain file and the
available (free) space on the disk. The problem is, that I get the size of
the file returned as a Long and the size of free disk space as UInt64.
Apparently, there are no function to convert a Long to a UInt64 or to
compare the two (I'm not expecting to convert the UInt64 to a Long
necessarily, but it should work the other way round, right?).
Short story: How to compare a Long with a UInt64?
Long story, please read the code below to see the problem described in the
very last comment statement
'------ snip - snip -------
Dim objDiskClass As System.Management.ManagementClass
Dim objDisks As System.Management.ManagementObjectCollection
Dim objDisk As System.Management.ManagementObject
Dim lFileSize As Long
Dim uiDiskSpace As System.UInt64
Dim objFileInfo = New FileInfo("MyFile.txt")
lFileSize = objFileInfo.Length
objDiskClass = New System.Management.ManagementClass("Win32_LogicalDisk")
objDisks = objDiskClass.GetInstances()
For Each objDisk In objDisks
If CStr(objDisk("Name")) = "D:" Then
uiDiskSpace = CType(objDisk("FreeSpace"), System.UInt64)
Exit For
End If
Next objDisk
'now I got the File Size as Long in lFileSize
'and the Free Disk Space as UInt64 in uiDiskSpace
'??? How can I compare the two ???
'------ snip - snip -------
Thank you for all of your help and have some great holidays too!
Wolfgang
I am using the following code to retrieve the size of a certain file and the
available (free) space on the disk. The problem is, that I get the size of
the file returned as a Long and the size of free disk space as UInt64.
Apparently, there are no function to convert a Long to a UInt64 or to
compare the two (I'm not expecting to convert the UInt64 to a Long
necessarily, but it should work the other way round, right?).
Short story: How to compare a Long with a UInt64?
Long story, please read the code below to see the problem described in the
very last comment statement
'------ snip - snip -------
Dim objDiskClass As System.Management.ManagementClass
Dim objDisks As System.Management.ManagementObjectCollection
Dim objDisk As System.Management.ManagementObject
Dim lFileSize As Long
Dim uiDiskSpace As System.UInt64
Dim objFileInfo = New FileInfo("MyFile.txt")
lFileSize = objFileInfo.Length
objDiskClass = New System.Management.ManagementClass("Win32_LogicalDisk")
objDisks = objDiskClass.GetInstances()
For Each objDisk In objDisks
If CStr(objDisk("Name")) = "D:" Then
uiDiskSpace = CType(objDisk("FreeSpace"), System.UInt64)
Exit For
End If
Next objDisk
'now I got the File Size as Long in lFileSize
'and the Free Disk Space as UInt64 in uiDiskSpace
'??? How can I compare the two ???
'------ snip - snip -------
Thank you for all of your help and have some great holidays too!
Wolfgang