Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

open command prompt window and change current working directory

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...