peer_2_peer_2
peer_2_peer_2

Reputation: 135

Retrieve file count without walking through entire file system

I am on a vxworks 6.9 platform. I want to know how many files are in a folder. The file system is DOSFS (FAT). The only way I know how to do this is to simply loop through every file in the folder and count. This gets very expensive the more files in the folder. Is there a more sensible way to do this? Does there exist some internal database or count of all files in a folder?

Upvotes: 1

Views: 310

Answers (1)

dbush
dbush

Reputation: 224082

The FAT filesystem does not keep track of the number of files it contains. What it does contain is:

  • A boot sector
  • A filesystem information sector (on FAT32) including:
    • Last number of known free clusters
    • Number of the most recently allocated cluster
  • Two copies of the file allocation table
  • An area for the root directory (on FAT12 and FAT16)
  • Data clusters

You'll need to walk the directory tree to get a count.

Upvotes: 2

Related Questions