以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]复制电脑文件到U盘空间不足的问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=59419)

--  作者:lindong
--  发布时间:2014/11/3 23:36:00
--  [求助]复制电脑文件到U盘空间不足的问题
在窗口内有一个按钮,单击该按钮,指定电脑上的文件夹复制到U盘上,当U盘空间不足时,会报错。想问一下高手,能否在U盘空间不够的情况下实现弹窗提示?或取消操作?
--  作者:y2287958
--  发布时间:2014/11/4 6:37:00
--  
支持
--  作者:Bin
--  发布时间:2014/11/4 8:17:00
--  
Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()

        Dim d As System.IO.DriveInfo
        For Each d In allDrives
            output.show("硬盘 : " & d.name)
            output.show("类型 : " & d.DriveType)
            If d.IsReady = True Then
                output.show("标题: " & d.VolumeLabel)
                output.show("格式: " & d.DriveFormat)
                output.show("对当前用户的可用空间: " & d.AvailableFreeSpace & " bytes")

                output.show("全部可用空间: " & d.TotalFreeSpace & " bytes")

                output.show("整个盘容量: " & d.TotalSize & "bytes ")
            End If
        Next

--  作者:有点甜
--  发布时间:2014/11/4 9:12:00
--  
 至于如何获取文件夹大小,那就需要用递归遍历所有的文件,获取每个文件的大小,相加得到
--  作者:lindong
--  发布时间:2014/11/4 12:38:00
--  
可以获取到磁盘信息,谢谢!
--  作者:lindong
--  发布时间:2014/11/5 2:01:00
--  

[此贴子已经被作者于2014-11-5 2:11:33编辑过]

--  作者:lindong
--  发布时间:2014/11/5 19:01:00
--  
虽然自己不会递归文件,但这段代码可以做到二级目录的文件,已经够用了,谢谢高人指点。现在把自己写的代码贴出来,希望有人可以改进一下就更好了!


Dim k As New System.IO.DirectoryInfo(Tables("表c").current("第一列") )
Dim dirs As String() =System.IO.Directory.GetDirectories(Tables("表c").current("第一列") )
For Each n As String In dirs
    Dim w As New System.IO.DirectoryInfo(n)
    Dim v As System.IO.FileInfo
    For Each v In w.GetFiles
        s2=s2+v.length
        t2=s2
    Next
Dim d As New System.IO.DirectoryInfo(Tables("表c").current("第一列") )
Dim s As Long
Dim t As Long
Dim sum As Long
Dim s2 As Long
Dim t2 As Long
Dim f As System.IO.FileInfo
For Each f In d.GetFiles
    s=s+f.length
    t=s
Next
Next
sum=t+t2
Dim t4 As Long
Dim allDrives() As System.IO.DriveInfo = System.IO.DriveInfo.GetDrives()
Dim d3 As System.IO.DriveInfo
For Each d3 In allDrives
    If d3.drivetype = 2 Then
        t4=d3.AvailableFreeSpace
    End If
Next
If sum < t4 Then
Forms("等待窗口").open()
Application.DoEvents
FileSys.CopyDirectory (Tables("表c").current("第一列") , Tables("表c").current("第二列") ,True)
Forms("等待窗口").close()
        MessageBox.show("复制成功")
Else
    MessageBox.show("磁盘空间不足")
End If
[此贴子已经被作者于2014-11-5 19:05:23编辑过]