# Why do I get this error when I specify a path in the windows command prompt?

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?

-
P.s. I wasn't overly sure about the appropriate title/tags for this question, suggestions are very welcome! –  RubenGeert Feb 4 '13 at 10:37
You might want to add some additional detail around what you are trying to do, and with what language. –  Steve Feb 4 '13 at 10:44

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

-
if I'd like to run multiple files from the same folder, then do I need to specify the full path each time? My cd command was an attempt to avoid that. Thanks for your help! –  RubenGeert Feb 4 '13 at 17:50
Yes, in the windows command prompt, change to the folder containing the python files with cd, the you can omit the full path; the filename is sufficient then: python srcfile.py. –  phoibos Feb 4 '13 at 20:39