How do you deal with lots of small files?

前端 未结 14 1768
慢半拍i
慢半拍i 2020-12-08 04:48

A product that I am working on collects several thousand readings a day and stores them as 64k binary files on a NTFS partition (Windows XP). After a year in production the

相关标签:
14条回答
  • 2020-12-08 05:31

    If you can calculate names of files, you might be able to sort them into folders by date, so that each folder only have files for a particular date. You might also want to create month and year hierarchies.

    Also, could you move files older than say, a year, to a different (but still accessible) location?

    Finally, and again, this requires you to be able to calculate names, you'll find that directly accessing a file is much faster than trying to open it via explorer. For example, saying
    notepad.exe "P:\ath\to\your\filen.ame"
    from the command line should actually be pretty quick, assuming you know the path of the file you need without having to get a directory listing.

    0 讨论(0)
  • 2020-12-08 05:31

    To create a folder structure that will scale to a large unknown number of files, I like the following system:

    Split the filename into fixed length pieces, and then create nested folders for each piece except the last.

    The advantage of this system is that the depth of the folder structure only grows as deep as the length of the filename. So if your files are automatically generated in a numeric sequence, the structure is only is deep is it needs to be.

    12.jpg -> 12.jpg
    123.jpg -> 12\123.jpg
    123456.jpg -> 12\34\123456.jpg
    

    This approach does mean that folders contain files and sub-folders, but I think it's a reasonable trade off.

    And here's a beautiful PowerShell one-liner to get you going!

    $s = '123456'
    
    -join  (( $s -replace '(..)(?!$)', '$1\' -replace '[^\\]*$','' ), $s )
    
    0 讨论(0)
提交回复
热议问题