[Tutor] tree problem
Roelof Wobben
rwobben at hotmail.com
Sun Sep 12 13:15:04 CEST 2010
Hello,
I have this problem.
Write a program named litter.py that creates an empty file named trash.txt in each subdirectory of a directory tree given the root of the tree as an argument (or the current directory as a default).
So I change the example to this :
def traverse(path, s='.\n', f=0, d=0):
path2file = os.path.join(path) *** pathfile contains the path
if os.path.isdir(path2file): **** if pathfile is a dir.
d += 1 ***** the is one more directory
if getdirlist(path2file): ****** if the outcome of getdirlist is the same as the current directory
s, f, d = traverse(path2file, '| ' + s, f, d) do this module again
else:
f += 1 ****** else f (number of files increases with 1
return s, f, d ****** return s , numbers of files and the number of directories.
When I try to make it run I get this message :
File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 31, in traverse
s, f, d = traverse(path2file, '| ' + s, f, d)
File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 31, in traverse
s, f, d = traverse(path2file, '| ' + s, f, d)
File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 31, in traverse
s, f, d = traverse(path2file, '| ' + s, f, d)
File "C:\Users\wobben\workspace\oefeningen\src\test.py", line 28, in traverse
if os.path.isdir(path2file):
File "C:\Python27\lib\genericpath.py", line 44, in isdir
return stat.S_ISDIR(st.st_mode)
File "C:\Python27\lib\stat.py", line 41, in S_ISDIR
return S_IFMT(mode) == S_IFDIR
RuntimeError: maximum recursion depth exceeded
I can't see why this happens.
I know I have to fish but I can't see what's wrong here.
So I hope someone can learn how to fish here.
Roelof
More information about the Tutor
mailing list