Finding out total and free disk space in .NET

前端 未结 9 1192
我在风中等你
我在风中等你 2021-01-04 03:08

I am trying to find a way to determine the total and available disk space in an arbitrary folder from a .NET app. By \"total disk space\" and \"available disk space\" in a f

9条回答
  •  一生所求
    2021-01-04 03:43

    Here's one more possibility that I've used for years. The example below is VBScript, but it should work with any COM-aware language. Note that GetDrive() works on UNC shares as well.

    Dim Tripped
    Dim Level
    
    Tripped = False
    Level   = 0
    
    Sub Read(Entry, Source, SearchText, Minimum, Maximum)
    
        Dim fso
        Dim disk
    
        Set fso  = CreateObject("Scripting.FileSystemObject")
    
        Set disk = fso.GetDrive(Source)
    
        Level = (disk.AvailableSpace / (1024 * 1024 * 1024))
    
        If (CDbl(Level) < CDbl(Minimum)) or (CDbl(Level) > CDbl(Maximum)) Then
            Tripped = True
        Else
            Tripped = False
        End If
    
    End Sub
    

提交回复
热议问题