I need to changed directory using batch file in PowerShell.
Let's say the batch file named go.bat has the two lines of code. And I'm in q: directory.
c: cd c:\abc\def
When I run
go.bat, I'm still in q:
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Just encountered this problem, I wanted to have a script for jumping to a directory which works in Powershell and CMD.
I could solve it by creating a script with the same name, one is a powershell script and the other a bat file:
Let us say the script is just called "def". If I type def in Powershell, it will run the ps1 version, if I type it in cmd, it will run the bat. You have to have duplicate files but you get to use the same named command between shells.
cd /D c:\abc\def
Use the /D switch to change current drive in addition to changing current directory for a drive -- although I'm not sure why what you tried isn't working...
If the folder doesn't exist you'll get an error message:
The system cannot find the path specified.
You can view some help on the
cd command by typing