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.
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.
Are you sure Y:
really is a valid drive letter?
Try os.chdir('C:')
and make sure that works. (It works for me.)
os.chdir('Y:')
worked, it doesn't do the same thing as a "cd /d Y:" does. See @abarnert's comment. –
Delly If this is a mapped network drive, your best bet is to use the UNC path instead of the mapped path. Also, try to use a raw r
string modifier when using paths under windows, if you're not using os.path.join
.
import os
print os.getcwd()
os.chdir(r'\\server\path')
print os.getcwd()
If you are doing (Drive:path\to\folder) try switching the slashes to (Drive:path/to/folder)
© 2022 - 2024 — McMap. All rights reserved.