急救:如何判断磁盘已满

hxfkof 2006-10-25 10:36:16
请问如何判断某个盘已满,因为我不断往盘里写入文件,如果满了就换别的盘,全满了就覆盖原来的.
还要如果判断哪个文件的创建日期是最旧的
...全文
205 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Hassle 2006-10-25
  • 打赏
  • 举报
回复
Option Explicit

'引用Microsoft Scripting Runtime

Private Sub Command1_Click()
Dim FSO As FileSystemObject

Set FSO = New FileSystemObject
MsgBox FSO.Drives("C").FreeSpace & "/" & FSO.Drives("C").TotalSize
Set FSO = Nothing
End Sub
happy_sea 2006-10-25
  • 打赏
  • 举报
回复
Declare Function GetDiskFreeSpace Lib "Kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTtoalNumberOfClusters As Long) As Long

Function GetDiskSpaceFree(ByVal strDrive As String) As Long
Const strSEP_DRIVE$ = ":"

Dim strCurDrive As String
Dim lDiskFree As Long

On Error Resume Next

strCurDrive = Left$(CurDir$, 2)

If InStr(strDrive, strSEP_DRIVE) = 0 Or Len(strDrive) > 2 Then
strDrive = Left$(strDrive, 1) & strSEP_DRIVE
End If

ChDrive strDrive

If Err <> 0 Then
lDiskFree = -1
Else
Dim lRet As Long
Dim lBytes As Long, lSect As Long, lClust As Long, lTot As Long

lRet = GetDiskFreeSpace(vbNullString, lSect, lBytes, lClust, lTot)
On Error Resume Next
lDiskFree = (lBytes * lSect) * lClust
If Err Then lDiskFree = 2147483647
End If

If lDiskFree = -1 Then
MsgBox Error$ & vbLf & _
"确定驱动器 " & strDrive & " 的磁盘可用空间时出错", _
vbExclamation, "Error"
End If

GetDiskSpaceFree = lDiskFree

ChDrive strCurDrive

Err = 0
End Function


Private Sub cmdFreeSpace_Click()
Dim k&

k& = GetDiskSpaceFree("d:\")

If k& = -1 Then
' Error
Else

MsgBox "磁盘d " & " 剩余空间为" & _
Format(k& / (2 ^ 20), "Fixed") & "Mb。"

End If
End Sub
VBToy 2006-10-25
  • 打赏
  • 举报
回复
Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, _
lpSectorsPerCluster As Long, _
lpBytesPerSector As Long, _
lpNumberOfFreeClusters As Long, _
lpTotalNumberOfClusters As Long) As Long
Private Sub Command1_Click()
Dim d As String
Dim SecpC As Long
Dim BpS As Long
Dim fC As Long
Dim tC As Long
Dim f As Double
GetDiskFreeSpace "d:", SecpC, BpS, fC, tC
f = CDbl(SecpC) * CDbl(BpS) * CDbl(fC)
d = "D盘剩余:" & f & " Byte"
Debug.Print SecpC, BpS, fC, tC, d

End Sub
mustudent 2006-10-25
  • 打赏
  • 举报
回复
.Net的话好弄点 vb用api
期待高人

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧