GetVolumeName() and GetVolumeInfo() on Windows
Posted: Wed Dec 03, 2025 2:27 pm
On Windows, the functions GetVolumeName() and GetVolumeInfo() return the correct results for existing volumes, but for all non-existent volumes, the result is a random value or the previously returned value.
Without my p_PrintHex() function, the result looks different, so I left it in the first two loops. Without the GetVolumeInfo() call, the last name found is repeated.
I hope it's only a not initialized variable.
Without my p_PrintHex() function, the result looks different, so I left it in the first two loops. Without the GetVolumeInfo() call, the last name found is repeated.
I hope it's only a not initialized variable.
Code: Select all
Function p_PrintHex(st$)
Local Debugstr$=""
For Local i=0 To StrLen(st$, #ENCODING_RAW)-1
Debugstr$=Debugstr$ ..FormatStr("%.2X", ByteVal(MidStr(st$,i,1, #ENCODING_RAW),#BYTE)).." "
Next
DebugPrint(Debugstr$)
EndFunction
Volumes=CreateList()
For i=65 To 72 ; A-H
InsertItem(Volumes, Chr(i)..":")
Next
InsertItem(Volumes, "df0:")
ForEach(Volumes,
Function(a, b)
n$=GetVolumeName(b)
DebugPrint(b, n$)
p_PrintHex(n$)
EndFunction
)
DebugPrint("\n--------------------\n")
ForEach(Volumes,
Function(a, b)
n$=GetVolumeName(b)
DebugPrint(b, n$)
p_PrintHex(n$)
space = GetVolumeInfo(b,#FREESPACE)
DebugPrint(space, "bytes are free on ",b)
EndFunction
)
DebugPrint("\n--------------------\n")
ForEach(Volumes,
Function(a, b)
n$=GetVolumeName(b)
DebugPrint(b, n$)
EndFunction
)
Sleep(10000)