0

Is there a Windows API for determining if a certain file (path) is on an NTFS filesystem?

If this can be somehow inferred from an existing Python API, all the better.

Idan K
  • 20,443
  • 10
  • 63
  • 83
  • related http://stackoverflow.com/questions/2800798/how-to-find-the-file-system-type-in-python – Dan D. Jul 24 '11 at 19:51

3 Answers3

1

Dont know how to do it in Python, but I assume that invoking C functions will be easy.

So in C open file handle bu CreateFile, you'll retrieve a handle to such file. Then call GetVolumeInformationByHandleW and check the lpFileSystemNameBuffer variable for "ntfs" string.

Yakeen
  • 2,142
  • 1
  • 17
  • 21
  • uh, just noticed the minimum required Windows version on this is Vista – Idan K Jul 25 '11 at 08:54
  • In the earlier versions you can use the GetVolumeInformation function as the reparse points were not supported by ntfs yet. – Yakeen Jul 25 '11 at 11:15
  • yeah, problem is it requires a root path which is less convenient, thanks though. – Idan K Jul 25 '11 at 16:51
  • 1
    Then you can step one layer lower and use ZwQueryVolumeInformationFile from ntdll.dll, which is present in XP+. GetVolumeInformationByHandleW is just forward to this function. See http://msdn.microsoft.com/en-us/library/ff567070%28v=VS.85%29.aspx – Yakeen Jul 27 '11 at 15:02
1

In python you can do:

import win32api
t = win32api.GetVolumeInformation(path)
print t[-1]

which will print ntfs if the path is on that filesystem type

(based on Yakeen's answer but also untested as i don't have a windows machine)

Dan D.
  • 73,243
  • 15
  • 104
  • 123
  • That's it, but this way it won't work on reparse points (like mounted volumes as directories), that's why working over file handle is safer. – Yakeen Jul 24 '11 at 20:20
0

depending on your needs, you can use GetFileAttributes and check ntfs File Attribute Constants.

mox
  • 6,084
  • 2
  • 23
  • 35
  • What exactly do you mean Mox? All of them are present just in special cases. – Yakeen Jul 25 '11 at 07:56
  • I meant, some attributes like FILE_ATTRIBUTE_ENCRYPTED or FILE_ATTRIBUTE_SPARSE_FILE are only available on a NTFS volume. These attributes can be used as hint to determine if a file is on an NTFS filesystem. – mox Jul 25 '11 at 18:31