Working with paths with spaces in NT

David beechd at gatsby.tafe.tas.edu.au
Wed Jun 13 08:28:04 EDT 2001


I got a different problem on my Win2K box (Python2.0)

File "G:\ses\oddstuff\dirlist.py", line 7, in getDirs
    os.chdir(path)
OSError: [Errno 22] Invalid argument: 'wordpfct.wpg'

which was due to the original line:

os.chdir(path)

At the end of the recursion I hit a file, hence the change below:

import os
import dircache
import re

def getDirs(path, tabs):
	dirlist = []
	if os.path.isdir(path):
		os.chdir(path)
		for dir in dircache.listdir("."):
			if os.path.isdir(dir):
				dirlist.append(dir)
		print dirlist
		for dir in dirlist:
			print dir
	        getDirs(dir, tabs + 1)

getDirs("e:/Documents and Settings/", 1)

Otherwise appeared to handle paths with spaces OK

David


David LeBlanc <whisper at oz.nospamnet> wrote in message news:<9fol5s$9d3$3 at 216.39.170.247>...
> In article <mailman.991890250.31525.python-list at python.org>, 
> tim.one at home.com says...
> > [David LeBlanc]
> > > import os
> > > import dircache
> > > import re
> > >
> > > def getDirs(path, tabs):
> > > 	dirlist = []
> > > 	os.chdir(path)
> > > 	for dir in dircache.listdir("."):
> > > 		if os.path.isdir(dir):
> > > 			dirlist.append(dir)
> > > 	print dirlist
> > > 	for dir in dirlist:
> > > 		print dir
> > > 		getDirs(dir, tabs + 1)
> > >
> > > getDirs("L:/languages/python", 1)



More information about the Python-list mailing list