Hab ich nur jetzt schnell aus einem Buch raus kopiert...
Weiß aber nicht obs funkt - wennst es ausprobiert hast, schreib einfach mal.
Code:
laufwerk = InputBox("Geben Sie den Laufwerksbuchstaben an!", "Laufwerk", _
"C:\")
ergebnis = FreeSpace(laufwerk)
if ergebnis<0 then
if ergebnis = -1 then
MsgBox "Es lag kein Datenträger im Laufwerk!",vbExclamation
elseif ergebnis = -2 then
MsgBox "Laufwerk " & laufwerk & " existiert nicht!",vbExclamation
end if
else
ergebnis2 = TotalSpace(laufwerk)
MsgBox "Freier Speicher auf Laufwerk " & _
laufwerk & ": "& FormatMB(ergebnis) & _
vbCr & "Speicherplatz insgesamt: "& _
FormatMB(ergebnis2), vbInformation
end if
function FreeSpace(lfw)
set fs = CreateObject _
("Scripting.FileSystemObject")
if fs.DriveExists(lfw) then
set lfwhandle = fs.GetDrive(lfw)
if lfwhandle.isReady then
FreeSpace = lfwhandle.FreeSpace
else
FreeSpace = -1
end if
else
FreeSpace = -2
end if
end function
function TotalSpace(lfw)
set fs = CreateObject("Scripting.FileSystemObject")
if fs.DriveExists(lfw) then
set lfwhandle = fs.GetDrive(lfw)
if lfwhandle.isReady then
TotalSpace = lfwhandle.TotalSize
else
TotalSpace = -1
end if
else
FreeSpace = -2
end if
end function
function FormatMB(bytes)
if bytes<1024 then
FormatMB = bytes & " Bytes"
elseif bytes<1024^2 then
FormatMB = FormatNumber(bytes/1024,2) & " KB"
elseif bytes<1024^3 then
FormatMB = FormatNumber(bytes/1024^2, 2) & " MB"
else
FormatMB = FormatNumber(bytes/1024^3, 2) & " GB"
end if
end function