opkcircles.blogg.se

Folder size 2.6
Folder size 2.6










Refer to os.py for the implementation of os.walk, posixmodule.c for the implementation of listdir and win32_stat (invoked by both isdir and getsize.) You can either use Anurag's solution, or try to call FindFirstFile/ FindNextFile directly and recursively (which should be comparable to the performance of a cygwin or other win32 port du -s some_directory.) That is 3x more system calls per file than Windows Explorer, plus memory allocation and manipulation overhead.

  • you then call getsize for each file returned by os.walk (which again calls GetFileAttributesEx).
  • os.walk and os.listdir will perform additional memory allocation, string and array operations etc.
  • os.walk then calls isdir for each file returned by os.listdir (which internally calls GetFileAttributesEx - or, prior to Win2k, a GetFileAttributes+ FindFirstFile combo) to redetermine whether to recurse or not.
  • any additional system calls made from this point onward can only make you slower than Windows Explorer.
  • folder size 2.6 folder size 2.6

  • os.walk first calls os.listdir (which internally calls FindFirstFile/ FindNextFile).
  • Python is unfortunately not your friend in this case. Windows Explorer almost certainly uses FindFirstFile/ FindNextFile to both traverse the directory structure and collect size information (through lpFindFileData) in one pass, making what is essentially a single system call per file.












    Folder size 2.6