I'm trying to use the cd
command in order to point to the folder where my file is located but I keep getting SyntaxError: invalid syntax
(see screenshot).
Could anyone please point out what I'm doing wrong here?
To complement @phoibos's answer, you are trying to change to a directory on another drive, you need to use the /d
switch when in the normal cmd console.
cd /d D:\folder
First, you're using cd
in a Python environment, which is not available here. You should use chdir
from os
module to change the current working path in Python.
Also, you use backslashes for defining the path, which need to be escaped. Either use D:\\back_this_up\\.....
or D:/back_this_up/......
.
Example:
import os
os.chdir("D:/back_this_up/your/desired/path")
and then do whatever you want to do.
If you want to use cd
(as you described in your question) you have to exit the Python interpreter with exit()
command and then use the syntax you tried before.
You're entering the cd
command within an instance of the python interactive interpreter (notice the >>>
at the beginning of the lines), not within the windows command prompt.
Try exiting python with CTRL+Z, then Enter. After this, enter your cd
command.
Edit:
Maybe you just want to run a python program? Then you would would have to run
python path\to\your\pythonfile.py
cd
command was an attempt to avoid that. Thanks for your help!
Commented
Feb 4, 2013 at 17:50
cd
, the you can omit the full path; the filename is sufficient then: python srcfile.py
.