A
albert kao
How do I recursively remove all the directories and files which begin
with '.'?
My test program rmdir.py does not do the job yet.
Please help.
C:\python>rmdir.py
C:\test\com.comp.hw.prod.proj.war\bin
['.svn', 'com']
d .svn
dotd C:\test\com.comp.hw.prod.proj.war\bin\.svn
Traceback (most recent call last):
File "C:\python\rmdir.py", line 14, in <module>
rmtree(os.path.join(curdir, d))
File "C:\Python31\lib\shutil.py", line 235, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "C:\Python31\lib\shutil.py", line 233, in rmtree
os.remove(fullname)
WindowsError: [Error 5] Access is denied: 'C:\\test\
\com.comp.hw.prod.proj.war\\bin\\.svn\\entries'
with '.'?
My test program rmdir.py does not do the job yet.
Please help.
Code:
#!c:/Python31/python.exe -u
import os
from shutil import *
root = "C:\\test\\com.comp.hw.prod.proj.war\\bin"
for curdir, dirs, files in os.walk(root):
print (curdir)
print (dirs)
for d in dirs:
print ("d " + d)
if d.startswith('.'):
print ("dotd " + os.path.join(curdir, d))
rmtree(os.path.join(curdir, d))
C:\python>rmdir.py
C:\test\com.comp.hw.prod.proj.war\bin
['.svn', 'com']
d .svn
dotd C:\test\com.comp.hw.prod.proj.war\bin\.svn
Traceback (most recent call last):
File "C:\python\rmdir.py", line 14, in <module>
rmtree(os.path.join(curdir, d))
File "C:\Python31\lib\shutil.py", line 235, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "C:\Python31\lib\shutil.py", line 233, in rmtree
os.remove(fullname)
WindowsError: [Error 5] Access is denied: 'C:\\test\
\com.comp.hw.prod.proj.war\\bin\\.svn\\entries'