0

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.
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

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'

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sergb
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.