Get free disk space

this works for me… using System.IO; private long GetTotalFreeSpace(string driveName) { foreach (DriveInfo drive in DriveInfo.GetDrives()) { if (drive.IsReady && drive.Name == driveName) { return drive.TotalFreeSpace; } } return -1; }

How to find the amount of free storage (disk space) left on Android? [duplicate]

Example: Getting human readable size like 1 Gb String memory = bytesToHuman(totalMemory()) /************************************************************************************************* Returns size in bytes. If you need calculate external memory, change this: StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath()); to this: StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); **************************************************************************************************/ public long totalMemory() { StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath()); long total = (statFs.getBlockCount() * statFs.getBlockSize()); return total; … Read more

How to check if IOException is Not-Enough-Disk-Space-Exception type?

You need to check the HResult and test against ERROR_DISK_FULL (0x70) and ERROR_HANDLE_DISK_FULL (0x27), which can be converted to HResults by OR‘ing with 0x80070000. For .Net Framework 4.5 and above, you can use the Exception.HResult property: static bool IsDiskFull(Exception ex) { const int HR_ERROR_HANDLE_DISK_FULL = unchecked((int)0x80070027); const int HR_ERROR_DISK_FULL = unchecked((int)0x80070070); return ex.HResult == HR_ERROR_HANDLE_DISK_FULL … Read more

Cross-platform space remaining on volume using python

import ctypes import os import platform import sys def get_free_space_mb(dirname): “””Return folder/drive free space (in megabytes).””” if platform.system() == ‘Windows’: free_bytes = ctypes.c_ulonglong(0) ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(dirname), None, None, ctypes.pointer(free_bytes)) return free_bytes.value / 1024 / 1024 else: st = os.statvfs(dirname) return st.f_bavail * st.f_frsize / 1024 / 1024 Note that you must pass a directory name for GetDiskFreeSpaceEx() … Read more

Get free space on internal memory

this post might fit well to your question. also check this thread. there is so much info here on SO. googled a bit and here is the solution (found at android git) File path = Environment.getDataDirectory(); StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlocks = stat.getAvailableBlocks(); return Formatter.formatFileSize(this, availableBlocks * blockSize);

Find size and free space of the filesystem containing a given file

This doesn’t give the name of the partition, but you can get the filesystem statistics directly using the statvfs Unix system call. To call it from Python, use os.statvfs(‘/home/foo/bar/baz’). The relevant fields in the result, according to POSIX: unsigned long f_frsize Fundamental file system block size. fsblkcnt_t f_blocks Total number of blocks on file system … Read more