hrrmsn / ffcleaner

cmd tool to cleanup littered directories (Files&Folders cleaner)
0 stars 0 forks source link

Cannot remove existing directory with 'rmtree' function of 'shutil' lib #29

Closed hrrmsn closed 7 years ago

hrrmsn commented 7 years ago

http://stackoverflow.com/questions/28528020/why-am-i-getting-windowserror-error-5-access-is-denied

hrrmsn commented 7 years ago
Traceback (most recent call last):
  File "ffcleaner.py", line 335, in overwrite
    shutil.rmtree(path)
  File "E:\Program Files\Python27\lib\shutil.py", line 244, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "E:\Program Files\Python27\lib\shutil.py", line 244, in rmtree
    rmtree(fullname, ignore_errors, onerror)
  File "E:\Program Files\Python27\lib\shutil.py", line 249, in rmtree
    onerror(os.remove, fullname, sys.exc_info())
  File "E:\Program Files\Python27\lib\shutil.py", line 247, in rmtree
    os.remove(fullname)
WindowsError: [Error 5] : '../ffcleaner-sandbox/text_files_cleaned\\document\\pdf\\\xcf\xee\xeb\xee\xed\xf1\xea\xe0\xff \xd1\xe0\xec\xee\xf3\xf7\xe8\xf2\xe5\xeb\xfc \xdf\xe7\xfb\xea \xcd\xd2\xccL.pdf'
hrrmsn commented 7 years ago

Removing directory contained a read-only file. 'rmtree' function of 'shutil' python library fails when it tries to remove read-only file. I found a solution in this articles. ~http://stackoverflow.com/questions/21261132/shutil-rmtree-to-remove-readonly-files~ (read) ~https://bugs.python.org/issue19643~ (read) ~http://stackoverflow.com/questions/1889597/deleting-directory-in-python~ (read)

The solution is a workaround unfortunately.

TODO. Need to refactor '_removereadonly' function. I need to understand more about how this works.

hrrmsn commented 7 years ago

I thought about the need to refactor 'remove_readonly' function and I decided that it isn't nessecary.

hrrmsn commented 7 years ago

DONE.