[Tutor] Cannot fix OSError (try/except)

Nick Lunt nick at javacat.f2s.com
Sat Jan 31 17:13:12 EST 2004


With the help I've received so far I've decided (but not yet coded) that the original 'if os.access('wherever', os.R_OK):' will be able to handle files passed on the command line fine, but directories will need to be walked so that any subdirectories/files can be handled seperately.

Something along the lines of 

arglist = sys.argv[2:]
for f in arglist:
	if os.path.isdir(f): # it's a dir
		<send it off to a func for a dir walk and access check>
	if os.access(f, os.R_OK): # it's a file
		<add it to the final list of files to be tarred>

Well that makes sense to me anyway - thanks to you folks ;)

Cheers
Nick.






On Sat, 31 Jan 2004 21:54:42 -0000
"Alan Gauld" <alan.gauld at blueyonder.co.uk> wrote:

> > You can pass the name of a directory.  If it can't read a file
> within
> > the directory, it abandons the rest of the directory contents.  I
> just
> > tested that.  The except will continue to the next file/directory in
> YOUR
> > list, but you've potentially skipped readable files in the directory
> with
> > an error.
> 
> But doesn't the OK check do the same? You would need to do a
> tree walk to avoid that, wouldn't you?
> 
> Alan G.



More information about the Tutor mailing list