Search code examples
c++.netfilewinapintfs

Check if file is sparse


I'd like to check if file located on ntfs file system is sparse. What function I need to use to check that?

As I know sparse files contain data pieces in separate streems so I tryed to list alternate streams via FindFirstStreamW and FindNextStreamW, but it doesn't show anything interesting with sparse files.


Solution

  • In Win32, use the GetFileAttributes() function, checking the result if the FILE_ATTRIBUTE_SPARSE_FILE attribute is present.

    In .NET, use the File.GetAttributes() method, checking the result if the FileAttributes.SparseFile attribute is present.