[Tutor] how to check a user input path for dirve existence

Alan Gauld alan.gauld at blueyonder.co.uk
Mon Apr 5 19:46:54 EDT 2004

> check to an attempt to create the directory, I won't have ruled
> out trying to create, say, J:\spam on a system without a J: drive.

This presupposes that drive letters can be part of a path, which 
kind of limits things to CP/M(do we get Python for CP/M?) and 
Windows/DOS. (I think they are the only OS's that use drive 
letters as part of a path? Macs use drives but they have 
names and no other distinguishing features...)

Given that limitation we know that the drive info can only consist 
of a single letter and a colon. So the only thing to test for is:

if path[1] == ':'

Which makes

> 2) Initialize asked_drivename to an empty string. Check if
> asked_dir has a ':' (in effect, checking to see if the string
> begins with a drive name), and if so, then extract the beginning
> of the string up to and including the colon to asked_drivename.

fairly trivial:

path = path[2:]

But checking that path.exists is always a good idea too!

Also my brain is still adjusting to Python & Programming after 
a weeks break so maybe I'm missing some complexity somewhere 
- like network drives maybe...

Alan G.

More information about the Tutor mailing list