Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

VB.Net – Get File Size / Free Space / Total Space

Posted on December 14, 2013September 2, 2019 By David Kittell
Private Function GetFileSize(ByVal MyFilePath As String) As Long
        Dim MyFile As New FileInfo(MyFilePath)
        Dim FileSize As Long = MyFile.Length
        Return FileSize
    End Function

    Public Function GetFreeSpace(ByVal Drive As String) As Long

        Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long

        Dim iAns As Long

        iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, lBytesTotal, lFreeBytes)
        If iAns > 0 Then

            Return BytesToMegabytes(lFreeBytes)
        Else
            Throw New Exception("Invalid or unreadable drive")
        End If


    End Function

    Public Function GetTotalSpace(ByVal Drive As String) As String

        Dim lBytesTotal, lFreeBytes, lFreeBytesAvailable As Long

        Dim iAns As Long

        iAns = GetDiskFreeSpaceEx(Drive, lFreeBytesAvailable, _
             lBytesTotal, lFreeBytes)
        If iAns > 0 Then

            Return BytesToMegabytes(lBytesTotal)
        Else
            Throw New Exception("Invalid or unreadable drive")
        End If
    End Function
Originally Posted on December 14, 2013
Last Updated on September 2, 2019
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code VB.NET

Post navigation

Previous post
Next post

Related Posts

MSSQL – Table/View Column Information

Posted on February 25, 2013October 26, 2015

Similar to MySQL – Table/View Column Information, this post will help with MSSQL tables and columns. exec sp_columns ‘<tablename>’ Cleaner Result: SET NOCOUNT ON DECLARE @tablename NVARCHAR(max) SET @tablename = <tablename> SELECT c.NAME ‘Column Name’ ,t.NAME ‘Data type’ ,c.max_length ‘Max Length’ , –c.precision , –c.scale , CASE c.is_nullable WHEN 0…

Read More

C# Clean String Input

Posted on April 4, 2014October 26, 2015

You can use the CleanInput method defined in this example to strip potentially harmful characters that have been entered into a text field that accepts user input. In this case, CleanInput strips out all non-alphanumeric characters except periods (.), at symbols (@), and hyphens (-), and returns the remaining string….

Read More

Reorganize Directory By File Count

Posted on May 26, 2020August 17, 2024

$filesperfolder = 1000 $sourcePath = "c:\Pictures" $destPath = "c:\Pictures\imgOrg" $i = 0 $folderNum = 1 if (!(Test-Path "$destPath")) { New-Item -Path "$destPath" -Type Directory -Force } Get-ChildItem "$sourcePath\*.jpg" | % { New-Item -Path ($destPath + "\" + $folderNum) -Type Directory -Force Move-Item $_ ($destPath + "\" + $folderNum) -Verbose $i++…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes