I've written a a.bat file and I want to use it at command prompt. for example I've written "d:" in this a.bat file. Where should I save this file that when I write "a" in command prompt , it goes to drive D ?
我写了一个a.bat文件,我想在命令提示符下使用它。例如,我在这个a.bat文件中写了“d:”。我应该在哪里保存这个文件,当我在命令提示符下写“a”时,它会转到驱动器D?
2 个解决方案
#1
2
If you are looking to execute the .bat file from the command prompt regardless of the command prompt's current path, then you need to save the .bat file in a directory that is included in the PATH system variable (assuming you are using windows).
如果要从命令提示符执行.bat文件而不管命令提示符的当前路径如何,则需要将.bat文件保存在PATH系统变量中包含的目录中(假设您使用的是Windows)。
For Example
if a.bat is saved in C:\MyDir\MySubDir
如果a.bat保存在C:\ MyDir \ MySubDir中
C:\>a.bat
will execute (i.e. the directory will change to D:> if C:\MyDir\MySubDir is in the PATH system variable. If not, you will get a message as follows
C:\> a.bat将执行(即如果C:\ MyDir \ MySubDir位于PATH系统变量中,目录将更改为D:>。如果不是,您将收到如下消息
'a.bat' is not recognized as an internal or external command, operable program or batch file.
'a.bat'不被识别为内部或外部命令,可操作程序或批处理文件。
The PATH variable is populated with a few paths by default, such as C:\Windows\System32. You can also add any path on the system to the PATH variable using the instructions contained in the link below (article is for Windows XP, but its largely the same for Win 7/8 once you get to the system properties).
默认情况下,PATH变量会填充一些路径,例如C:\ Windows \ System32。您还可以使用以下链接中包含的说明将系统上的任何路径添加到PATH变量(文章适用于Windows XP,但是一旦进入系统属性,它与Win 7/8大致相同)。
#2
0
save it in the current directory and navigate there to execute it without messing with the path if you aren't certain how to do that. if you do use the path, back it up the first few times.
将它保存在当前目录中并在那里导航以执行它而不会弄乱路径,如果您不确定如何做到这一点。如果您使用该路径,请在前几次备份。
#1
2
If you are looking to execute the .bat file from the command prompt regardless of the command prompt's current path, then you need to save the .bat file in a directory that is included in the PATH system variable (assuming you are using windows).
如果要从命令提示符执行.bat文件而不管命令提示符的当前路径如何,则需要将.bat文件保存在PATH系统变量中包含的目录中(假设您使用的是Windows)。
For Example
if a.bat is saved in C:\MyDir\MySubDir
如果a.bat保存在C:\ MyDir \ MySubDir中
C:\>a.bat
will execute (i.e. the directory will change to D:> if C:\MyDir\MySubDir is in the PATH system variable. If not, you will get a message as follows
C:\> a.bat将执行(即如果C:\ MyDir \ MySubDir位于PATH系统变量中,目录将更改为D:>。如果不是,您将收到如下消息
'a.bat' is not recognized as an internal or external command, operable program or batch file.
'a.bat'不被识别为内部或外部命令,可操作程序或批处理文件。
The PATH variable is populated with a few paths by default, such as C:\Windows\System32. You can also add any path on the system to the PATH variable using the instructions contained in the link below (article is for Windows XP, but its largely the same for Win 7/8 once you get to the system properties).
默认情况下,PATH变量会填充一些路径,例如C:\ Windows \ System32。您还可以使用以下链接中包含的说明将系统上的任何路径添加到PATH变量(文章适用于Windows XP,但是一旦进入系统属性,它与Win 7/8大致相同)。
#2
0
save it in the current directory and navigate there to execute it without messing with the path if you aren't certain how to do that. if you do use the path, back it up the first few times.
将它保存在当前目录中并在那里导航以执行它而不会弄乱路径,如果您不确定如何做到这一点。如果您使用该路径,请在前几次备份。