Batch file for starting powershell in a specific directory

7,389

Solution 1

Close Nate, but that doesn't work when I run it on a "New Folder". Had to move the CD outside the single quotes to make it work.

powershell.exe -noexit -command "cd 'c:\New folder'"
powershell.exe -noexit -command "cd 'c:\self\pooja\edu n career\programs\python'"

Solution 2

I'm not quite sure what your directory folder looks like, but assuming that edu n career is one directory, you shouldn't need to escape that with its own set of double quotes, you should be able to change the code to

powershell.exe -noexit -command "'cd c:\self\pooja\edu n career\programs\python'"

If you look at the command in a text editor with syntax highlighting, you can see that the edu n career is actually not part of the command.

code

Share:
7,389

Related videos on Youtube

Pooja
Author by

Pooja

Updated on September 18, 2022

Comments

  • Pooja
    Pooja over 1 year

    I am learning to program in python through the book "Learn python the hard way". Therefore I use powershell to run my programs. Since I had to manually change the directory every-time I started powershell , I wrote a batch file to automate it.

    The command I wrote is :

    powershell.exe -noexit -command "'cd c:\self\pooja\"edu n career"\programs\python'"
    

    The problem is that it runs but opens the directory of "programs" only. Why is it not changing to python directory?

    Finally , I did it by setting the "Start in" field in the shortcut property of powershell but I want to know why the batch file is not working as expected.

  • Pooja
    Pooja over 6 years
    I am trying to run the batch file again but cmd starts and closes immediately . I have written it same as you told.