How do I recursively remove all the directories and files which begin with '.'?
My test program does not do the job yet.
Please help.
#!c:/Python31/python.exe -u
import os
from shutil import *
root = "C:\\test\\\\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))


d .svn
dotd C:\test\\bin\.svn
Traceback (most recent call last):
File "C:\python\", line 14, in <module>
rmtree(os.path.join(curdir, d))
File "C:\Python31\lib\", line 235, in rmtree
onerror(os.remove, fullname, sys.exc_info())
File "C:\Python31\lib\", line 233, in rmtree
WindowsError: [Error 5] Access is denied: 'C:\\test\

You should not be deleting those directories. The . directory is the current directory; the .. is the parent directory of the . directory. Every directory has those two pointers even when its empty. The filesystem will not let you remove those. The . and .. are essential to maintaining the directory tree by the file system.