|
Programs
File Backupper
Digitize Plot To Data
Ready Replace
Scrabbler
Tutorials
Comsol 4.2 Tutorials
Gwyddion Tutorials
VB 6.0 Tutorials
Tutorials: else
|
|
VB Tutorials |
VB 6.0 Tutorial: Check free disc size/
available space
This tutorial shows you how to use a windows API in order to get the
free disc size.
Solution
You type in the drive you want to know the free space
of and get a message box for that:
Keywords:
VB6.0, Visual Basic 6
check free target space, Drive's physical free Space, free Disc Space,
Total Disc Space
Win32 API
Download VB6.0 Project with solution
The source code for this project:
Option Explicit
'Dieser Source stammt von http://www.soft-hummingbird.com
'und kann frei verwendet werden. Für eventuelle Schäden
'wird nicht gehaftet.
'This source code originates from http://www.soft-hummingbird.com
'it is as-is without any warranty and can be used freely
'In no event shall the author be held liable for any damages arising
from the use of this code
Private Declare Function
SHGetDiskFreeSpace Lib "shell32" Alias "SHGetDiskFreeSpaceA" (ByVal
pszVolume As String, pqwFreeCaller As Currency, pqwTot As Currency,
pqwFree As Currency) As Long
Private Sub Command1_Click()
MsgBox "Free space on " & Text1 &
vbCrLf & Format(CheckFreeSpaceOnDisc(Text1), "###,###,###,##0") & "
Byte"
End Sub
'gibt die Anzahl der bytes zurück oder bei
auftreten von fehler -1
'Benutzung: text1 = FileSizeH(CheckFreeSpaceOnDisc("c"))
Function CheckFreeSpaceOnDisc(ByVal
Drive As String)
As Currency
Dim FreeForCaller
As Currency, Tot As Currency,
Free As Currency
On Error GoTo fehler
If Drive = "" Then
CheckFreeSpaceOnDisc = -1: Exit Function
If Len(Drive) = 1
Then Drive = Drive & ":\"
If Len(Drive) = 2 And
Right$(Drive, 1) = ":" Then
Drive = Drive & "\"
SHGetDiskFreeSpace Drive, FreeForCaller, Tot, Free
FreeForCaller = FreeForCaller * 10000
Tot = Tot * 10000
Free = Free * 10000
'Format$(FreeForCaller,
"###,###,###,##0") & " Byte"
CheckFreeSpaceOnDisc = FreeForCaller
Exit Function
fehler: CheckFreeSpaceOnDisc = -1
End Function
|
Download this source code embedded in an easy to use Visual Basic 6.0 project:
(3 kB)
|
|