How can I change drives using python os?

aensm picture aensm · Jun 15, 2012 · Viewed 25.2k times · Source

I'm trying to change the current directory from C: to Y: I tried:

import os
os.chdir('Y:')

but I keep getting an error saying that it can't locate the drive. Essentially I'm looking for the equivalent of the

cd /d

command in cmd.

Answer

Jon-Eric picture Jon-Eric · Jun 15, 2012

Are you sure Y: really is a valid drive letter?

Try os.chdir('C:') and make sure that works. (It works for me.)