Directory file size calculation - how to make it faster?

前端 未结 8 1417
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 11:10

Using C#, I am finding the total size of a directory. The logic is this way : Get the files inside the folder. Sum up the total size. Find if there are sub directories. Then

8条回答
  •  悲&欢浪女
    2020-12-08 11:31

    I don't think it will change a lot, but it might go a little faster if you use the API functions FindFirstFile and NextFile to do it.

    I don't think there's any really quick way of doing it however. For comparison purposes you could try doing dir /a /x /s > dirlist.txt and to list the directory in Windows Explorer to see how fast they are, but I think they will be similar to FindFirstFile.

    PInvoke has a sample of how to use the API.

提交回复
热议问题