• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2281
  • Last Modified:

How to programmatically detect Storage Card capacity and free space?

Hi all,

how can I programmatically obtain how much space left on given SD Card? I can easily enumerate then on Windows Mobile, but a bit lost on their info retrieval. I can get the info about Program/Storage memory without any problems.

It seems that I miss some easy bit for SD cards :)

1 Solution
Public Function GetSize(ByRef directoryName As String) As DiskFreeSpace

Dim result As New DiskFreeSpace

If GetDiskFreeSpaceEx(directoryName, result.FreeBytesAvailable,
result.TotalBytes, result.TotalFreeBytes) = False Then

Throw New
System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error(), "Error
retrieving free disk space")

End If

Return result

End Function

Public Structure DiskFreeSpace

Public FreeBytesAvailable As Long

Public TotalBytes As Long

Public TotalFreeBytes As Long

End Structure

Private Declare Function GetDiskFreeSpaceEx Lib "coredll.dll" (ByVal
directoryName As String, ByRef freeBytesAvailable As Int32, ByRef totalBytes
As Int32, ByRef totalFreeBytes As Int32)

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Freespace As New DiskFreeSpace
Freespace = GetSize("\")
End Sub
alexey_gusevAuthor Commented:
Thanks, Mikal!

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now