Page 1 of 1

GetVolumeName() and GetVolumeInfo() on Windows

Posted: Wed Dec 03, 2025 2:27 pm
by Flinx
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.

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)

Re: GetVolumeName() and GetVolumeInfo() on Windows

Posted: Fri Dec 05, 2025 7:47 pm
by airsoftsoftwair
Flinx wrote: Wed Dec 03, 2025 2:27 pm I hope it's only a not initialized variable.
Actually, this was because on Windows Hollywood wasn't checking if the drive name specified exists. Of course those functions should fail if the specified drive doesn't exist. Fixed this now, thanks for reporting!

Code: Select all

- Fix [Windows]: GetVolumeName() and GetVolumeInfo() didn't fail when the specified drive name didn't exist