A
albert kao
I want to walk a directory and ignore all the files or directories
which names begin in '.' (e.g. '.svn').
Then I will process all the files.
My test program walknodot.py does not do the job yet.
Python version is 3.1 on windows XP.
Please help.
C:\python>walknodot.py
dirpath C:\test\com.comp.hw.prod.proj.war\bin
dirpath C:\test\com.comp.hw.prod.proj.war\bin
dir .svn
dir com
[]
dirpath C:\test\com.comp.hw.prod.proj.war\bin\.svn
dirpath C:\test\com.comp.hw.prod.proj.war\bin\.svn
....
I do not expect C:\test\com.comp.hw.prod.proj.war\bin\.svn to appear
twice.
Please help.
which names begin in '.' (e.g. '.svn').
Then I will process all the files.
My test program walknodot.py does not do the job yet.
Python version is 3.1 on windows XP.
Please help.
Code:
#!c:/Python31/python.exe -u
import os
import re
path = "C:\\test\\com.comp.hw.prod.proj.war\\bin"
for dirpath, dirs, files in os.walk(path):
print ("dirpath " + dirpath)
p = re.compile('\\\.(\w)+$')
if p.match(dirpath):
continue
print ("dirpath " + dirpath)
for dir in dirs:
print ("dir " + dir)
if dir.startswith('.'):
continue
print (files)
for filename in files:
print ("filename " + filename)
if filename.startswith('.'):
continue
print ("dirpath filename " + dirpath + "\\" + filename)
# process the files here
C:\python>walknodot.py
dirpath C:\test\com.comp.hw.prod.proj.war\bin
dirpath C:\test\com.comp.hw.prod.proj.war\bin
dir .svn
dir com
[]
dirpath C:\test\com.comp.hw.prod.proj.war\bin\.svn
dirpath C:\test\com.comp.hw.prod.proj.war\bin\.svn
....
I do not expect C:\test\com.comp.hw.prod.proj.war\bin\.svn to appear
twice.
Please help.