How to get size of drive?
How to get size of drive?
Hello, i want to read out the total size or capacity of a drive letter, for example the disk size of drive c:\. how can i do that?
Re: How to get size of drive?
Hi
For Windows the simple approach
For Windows the simple approach
Code: Select all
Global Dim HDAvailableSpace.q(0)
Global Dim HDCapacity.q(0)
Global Dim HDFreeSpace.q(0)
Procedure GetDiskFreeSpace(drive$)
SetErrorMode_(#SEM_FAILCRITICALERRORS)
GetDiskFreeSpaceEx_(@drive$, HDAvailableSpace(), HDCapacity(), HDFreeSpace())
SetErrorMode_(0)
EndProcedure
GetDiskFreeSpace("c:")
Debug "HD Capacity : "+Str(HDCapacity(0)/1024/1024/1024)+" GB"
Debug "Free Space : "+Str(HDFreeSpace(0)/1024/1024/1024)+" GB"
Debug "Used Space : "+Str((HDCapacity(0)-HDFreeSpace(0))/1024/1024/1024)+" GB"
Egypt my love
Re: How to get size of drive?
If the disk is smaller than one gigabyte, its size will be clear.
Code: Select all
Define total_bytes.q
; Rounding to 3 digits after a period
Procedure.s FormatSizeDisk(Num.q)
Protected.s snum = StrF(Num/1024)
Protected.f total_gb = ValF(snum)
total_gb = total_gb/1048576
snum =StrF(total_gb,3)
ProcedureReturn snum
EndProcedure
If GetDiskFreeSpaceEx_("C:", 0, @total_bytes, 0)
Debug FormatSizeDisk(total_bytes) + " GB"
EndIf
Re: How to get size of drive?
Thank you that was exactly what i needed.
Re: How to get size of drive?
Does this code get rid of 4 messages that there is no disk in the Card Reader?
No computer to check. This problem exists in this program
Re: How to get size of drive?
If needed, for formatting in GB, MB, KB,... I use the procedure SizeIt, found here
Code: Select all
Define Total_bytes.q, Total_FreeBytes.q
Procedure.s SizeIt(Value.q)
Protected Unit=0, Byte.q, Pos.l, nSize.s
Byte = Value
While Byte >= 1024
Byte / 1024 : Unit + 1
Wend
If Unit : nSize = StrD(Value/Pow(1024, Unit), 15) : Pos.l = FindString(nSize, ".") : Else : nSize = Str(Value) : EndIf
If Unit : If Pos < 4 : nSize = Mid(nSize, 1, Pos+2) : Else : nSize = Mid(nSize, 1, Pos-1) : EndIf : EndIf
ProcedureReturn nSize +Space(1)+ StringField("b ,KB,MB,GB,TB,PB", Unit+1, ",")
EndProcedure
If GetDiskFreeSpaceEx_("C:", 0, @Total_Bytes, @Total_FreeBytes)
Debug "Space available: " + SizeIt(Total_Bytes) + " - Used space: " + SizeIt(Total_Bytes - Total_FreeBytes) + " - Free space: " + SizeIt(Total_FreeBytes)
EndIf
Re: How to get size of drive?
In that function I have an alignment to the right and the size is also determined visually by the protrusion of the numbers to the left.
To determine the size, I use 3 digit numbers and a prefix so that the width is the same. I use it in this program.
Code: Select all
Procedure.s _ShortFileSize(Bytes.q)
Protected res.s
Select Bytes
Case 10995116277760 To 109951162777600 ; 10 - 100 TB
res = StrD(Round(Bytes / 109951162777.6, #PB_Round_Nearest)/10.0) + " TB"
Case 1000000000000 To 10995116277759 ; 1000 GB - 10 TB
res = StrD(Round(Bytes / 10995116277.76, #PB_Round_Nearest)/100.0) + " TB"
Case 107374182400 To 999999999999 ; 100 - 999 GB
res = StrD(Round(Bytes / 1073741824, #PB_Round_Nearest)) + " GB"
Case 10737418240 To 107374182399 ; 10 - 100 GB
res = StrD(Round(Bytes / 107374182.4, #PB_Round_Nearest)/10.0) + " GB"
Case 1000000000 To 10737418239 ; 1000 MB - 10 GB
res = StrD(Round(Bytes / 10737418.24, #PB_Round_Nearest)/100.0) + " GB"
Case 104857600 To 999999999 ; 100 - 999 MB
res = StrD(Round(Bytes / 1048576, #PB_Round_Nearest)) + " MB"
Case 10485760 To 104857599 ; 10 - 100 MB
res = StrD(Round(Bytes / 104857.6, #PB_Round_Nearest)/10.0) + " MB"
Case 1000000 To 10485759 ; 1000 KB - 10 MB
res = StrD(Round(Bytes / 10485.76, #PB_Round_Nearest)/100.0) + " MB"
Case 102400 To 999999 ; 100 - 999 KB
res = StrD(Round(Bytes / 1024, #PB_Round_Nearest)) + " KB"
Case 10240 To 102399 ; 10 - 100 KB
res = StrD(Round(Bytes / 102.4, #PB_Round_Nearest)/10.0) + " KB"
Case 1000 To 10239 ; 1000 B - 10 KB
res = StrD(Round(Bytes / 10.24, #PB_Round_Nearest)/100.0) + " KB"
Case 0 To 999
res = StrD(Bytes )+ " B"
EndSelect
ProcedureReturn res
EndProcedure
Debug _ShortFileSize(100000)
Debug _ShortFileSize(10000000)
Debug _ShortFileSize(1000000000)
Debug _ShortFileSize(100000000000)
Re: How to get size of drive?
Good indeed, to respect the alignment as in your use in File scannerAZJIO wrote: ↑Wed Jan 19, 2022 11:46 pm In that function I have an alignment to the right and the size is also determined visually by the protrusion of the numbers to the left.
To determine the size, I use 3 digit numbers and a prefix so that the width is the same. I use it in this program.
The SizeIt() procedure can also be useful for formatting a single value without the need for alignment.