Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm terribly new to scripting on windows. Using windows 7 64.

I'm trying to make a .bat file that I can double click, and have it open a command prompt and automatically cd me to a certain directory.

I tried making a .bat file with

@ECHO OFF
cmd "cd C:mydestination"

Which opens what looks like a command prompt, but doesn't seem to let me type any commands.

I then tried:

@ECHO OFF
start cmd "cd C:mydestination"

But this just sent me into a loop opening tons and tons of prompts until my computer crashed :) The .bat file was located in the destination directory if that matters.

question from:https://stackoverflow.com/questions/4717352/open-command-prompt-window-and-change-current-working-directory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

This works for me:

@ECHO OFF
cmd.exe /K "cd C:mydestination && C:"

The quoted string is actually two commands (separated by a double ampersand): The first command is to change to the specified directory, the second command is to change to the specified drive letter.

Put this in a batch (.BAT) file and when you execute it you should see a Command Prompt window at the specified directory.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...