Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Available space on NAS
Message
From
20/02/2014 23:20:47
 
 
To
20/02/2014 22:53:35
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01594835
Message ID:
01594857
Views:
38
The following is the implementation of using DIR to get the available disk space of anything:
    ' Get the available disk space in a universal way
    Public Function GetAvailableDiskSpace() As Boolean
        Dim lcLine As String = ""
        Dim lcProviderName As String = ""
        Dim lcVolumeName As String = ""
        Dim lnLocation As Integer = 0
        Dim loProcessFile As Framework.ProcessFile = New Framework.ProcessFile(oApp)

        ' Reset the values
        cMessage = ""
        nFreeSpace = 0

        ' Initialization
        lcProviderName = Trim(cProviderName)
        lcVolumeName = Trim(cVolumeName)

        ' Execute the command
        loProcessFile.cWorkingDirectory = "c:\Windows\System32"
        loProcessFile.cFileName = "c:\Windows\System32\cmd.exe"
        loProcessFile.cArguments = "/c dir \\" + lcProviderName + "\" + lcVolumeName + " | find /i ""bytes free"""
        If Not loProcessFile.Process() Then
            cMessage = loProcessFile.cMessage
            Return False
        End If

        ' Initialization
        lcLine = loProcessFile.cOutput

        ' Parse the number of bytes
        lnLocation = oApp.At(" Dir(s) ", lcLine)
        lcLine = Mid(lcLine, lnLocation + 9)
        lnLocation = oApp.At(" bytes free", lcLine)
        lcLine = Mid(lcLine, 1, lnLocation - 1)

        ' Remove the spaces
        lcLine = oApp.StrTran(lcLine, Chr(255), "")

        ' Remove the commas
        lcLine = oApp.StrTran(lcLine, ",", "")

        ' Initialization
        nFreeSpace = Val(lcLine)

        Return True
    End Function
It does not give me the total available disk space, but at least, I can know how much remains.

This contains references to my framework but it should give a good idea on how to extract it using the DIR command.

On Windows 7, the delimiter is CHR(255). But, on most OS, the delimiter is a comma.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Reply
Map
View

Click here to load this message in the networking platform