0

What is the Microsoft Windows equivalent of Python 2.7 os.statvfs(pathname).f_avail for Linux? This counts the number of free inodes. In Windows, this would be the number of free MFT entries, or how many files can be created in the path.

I am looking for something that works with Python 2.7 with NTFS and FAT32.

Andrew
  • 1,619
  • 3
  • 19
  • 24

1 Answers1

0

There is no equivalent, because there is no fixed limit to the number of files that can be created. You can continue creating files until you run out of disk space.

If you can't remove the logic that uses f_avail, returning a sufficiently large constant, e.g., sys.maxint, would probably be close enough. [Edit: on second thoughts, returning sys.maxint would probably be an invitation to an integer overflow. An arbitrary number like 1 billion would be safer.]

FAT16 had a limit to the number of files that could be located in the root directory, but this does not apply to FAT32.

Harry Johnston
  • 35,639
  • 6
  • 68
  • 158
  • Thanks. OK, I noticed that I can create empty files on NTFS until the whole partition is full, but when I delete them, the MFT stays bloated and occupies most of the partition. How many files can I create until the MFT starts growing? – Andrew Mar 31 '14 at 04:54
  • I don't believe there's any truly reliable way to estimate this, and I can't imagine what you could usefully do with the information if you had it. However, there's some sample code here http://stackoverflow.com/a/7459109/886887 for enumerating the MFT (to count the existing files) and if you assume that each file uses exactly one file record segment then the approach here http://stackoverflow.com/a/11337898/886887 lets you estimate how many file records the MFT can currently hold. – Harry Johnston Mar 31 '14 at 20:00
  • (Of course you can't do this in Python, and it also requires admin privilege, and will be slow on disks with lots of files.) – Harry Johnston Apr 01 '14 at 00:01