Search code examples
pythonwindowscommandcd

Windows Command Line: CD & Execute Python


I'm having trouble executing a python script from Windows 7 Command Prompt. I've tried many different commands to run the script. Whether it's:

python e:\filepath\pythonScript.py
python pythonScript.py
cd\ & pythonScript.py
cd\ && e:\filepath\pythonScript.py

I keep getting the same:

[Errno 2] No such file or directory

Whenever I use the command:

dir

It prints the contents of the c: drive even when I use:

cd c: && dir

If anyone could shed some light on changing directories and executing python scripts in Windows 7, I'd greatly appreciate it.


Solution

  • if you are talking about changing to a new drive just type the drive letter followed by colon

    C:\>e:
    E:\>dir
    
    
    Volume in drive E has no label.
     Volume Serial Number is 9016-4EF8
    
     Directory of E:\
    18-Apr-14  02:16 AM    <DIR>          assets
    01-May-14  04:22 AM    <DIR>          store
    06-Jun-14  09:32 AM                22 test.py
    
    E:\>cd assets
    
    
    E:\assets>python test.py
    hello world
    

    or

    C:\>e: && cd assets && dir
     Volume in drive E has no label.
     Volume Serial Number is 9016-4EF8
    
     Directory of E:\assets
    

    or

      C:\>e: && cd \  && cd assets && dir
           ^     ^          ^           ^
    ch drive && go root&&go fldr && list foldr contents