windows - python win32com FileSystemObject failed on getting huge folder -


my test code is:

#!/usr/bin/env python import win32com.client  def getfoldersizequick(target_folder):     fso = win32com.client.dispatch("scripting.filesystemobject")     fobj = fso.getfolder(target_folder)     return fobj.size  print(getfoldersizequick("d:/pytools")) print(getfoldersizequick("d:/cygwin")) 

the result is:

d:\>python a.py 160659697 traceback (most recent call last):   file "a.py", line 10, in <module>     print(getfoldersizequick("d:/cygwin"))   file "a.py", line 7, in getfoldersizequick     return fobj.size   file "d:\applications\python33\lib\site-packages\win32com\client\dynamic.py", line 511, in __getattr__     ret = self._oleobj_.invoke(retentry.dispid,0,invoke_type,1) pywintypes.com_error: (-2147352567, '发生意外。', (0, none, none, none, 0, -2146828218), none) 

the first call getfoldersizequick on d:/pytools folder works. it's 153mb. second call failed. folder d:/cygwin 12.6gb.

i working on windows 7 python3.3.0 32bit version. think problem happened on 32bit or 64bit store result. 32bit int can not store 12.6gb size.

what real problem here, , how fix it?

that's neither directory size nor 32/64-bit problem. it's not python2 or python3 problem.

your error translates "no access allowed!"

the simpliest way testing create directory owner allowed read , others have no rights @ all. take directory input - you'll same error, if directory empty. example local "c:\system volume information".

digging little deeper: errorcodes given python signed, whereas reasonable lookup microsoft describes , expects them unsigned. kudos eb in this thread , tim peters in this thread, using examples, you'll reasonable error-codes.

import win32com.client import pywintypes  def get_folder_size(target_folder):     fso = win32com.client.dispatch("scripting.filesystemobject")     fobj = fso.getfolder(target_folder)     return fobj.size   if __name__ == '__main__':     try:         get_folder_size('c:/system volume information')     except pywintypes.com_error, e:         print e  # debug, have see indices         print hex(e[0]+2**32), hex(e[2][5]+2**32) 

now search both of hex digits, 2nd 1 should lead lot of "you not allowed to..." queries , answers.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -