Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 在文件夹中打开cmd而不在该文件夹中_Windows_Batch File_Cmd - Fatal编程技术网

Windows 在文件夹中打开cmd而不在该文件夹中

Windows 在文件夹中打开cmd而不在该文件夹中,windows,batch-file,cmd,Windows,Batch File,Cmd,我想创建一个快捷方式bat或exe,它将在快捷方式/bat/exe所在的当前路径中的特定文件夹中打开命令行 我的例子是快捷方式/bat/exe位于 C:\Users\"user"\Desktop 我想在文件夹中打开cmd C:\Users\"user"\Desktop\Folder 但我不希望它依赖于完整的路径。我想能够将exe和文件夹一起移动到另一个位置,它仍然可以工作。因此,我希望exe在当前路径+\文件夹中启动cmd.exe %windir%\system32\cmd.exe +

我想创建一个快捷方式bat或exe,它将在快捷方式/bat/exe所在的当前路径中的特定文件夹中打开命令行

我的例子是快捷方式/bat/exe位于

C:\Users\"user"\Desktop
我想在
文件夹中打开cmd

C:\Users\"user"\Desktop\Folder
但我不希望它依赖于完整的路径。我想能够将exe和文件夹一起移动到另一个位置,它仍然可以工作。因此,我希望exe在当前路径+\文件夹中启动cmd.exe

%windir%\system32\cmd.exe  +  \Folder
你可以把“cd文件夹”放在bat文件中

exe将取决于您使用什么来创建它,并且不知道快捷方式

您还可以在bat文件中使用%cd%来获取当前路径

C:\Users\user>echo%windir%\system32\cmd.exe%cd%\Folder

C:\Windows\system32\cmd.exe C:\Users\user\Folder

您可以将“cd Folder”放入bat文件中

exe将取决于您使用什么来创建它,并且不知道快捷方式

您还可以在bat文件中使用%cd%来获取当前路径

C:\Users\user>echo%windir%\system32\cmd.exe%cd%\Folder


C:\Windows\system32\cmd.exe C:\Users\user\Folder

有关文件名/路径列表,请参见
call/?
。这是批处理而不是快捷方式<代码>%0
是批处理文件

cd "%~dp0\folder"
已增强批处理参数(%n)的替换。你可以 现在使用以下可选语法:

  %~1         - expands %1 removing any surrounding quotes (")
   %~f1        - expands %1 to a fully qualified path name
   %~d1        - expands %1 to a drive letter only
   %~p1        - expands %1 to a path only
   %~n1        - expands %1 to a file name only
   %~x1        - expands %1 to a file extension only
   %~s1        - expanded path contains short names only
   %~a1        - expands %1 to file attributes
   %~t1        - expands %1 to date/time of file
   %~z1        - expands %1 to size of file
   %~$PATH:1   - searches the directories listed in the PATH
                  environment variable and expands %1 to the fully
                  qualified name of the first one found.  If the
                  environment variable name is not defined or the
                  file is not found by the search, then this
                  modifier expands to the empty string
可以组合修改器以获得复合结果:

  %~dp1       - expands %1 to a drive letter and path only
   %~nx1       - expands %1 to a file name and extension only
   %~dp$PATH:1 - searches the directories listed in the PATH
                  environment variable for %1 and expands to the
                  drive letter and path of the first one found.
   %~ftza1     - expands %1 to a DIR like output line

有关文件名/路径的列表,请参见
call/?
。这是批处理而不是快捷方式<代码>%0是批处理文件

cd "%~dp0\folder"
已增强批处理参数(%n)的替换。你可以 现在使用以下可选语法:

  %~1         - expands %1 removing any surrounding quotes (")
   %~f1        - expands %1 to a fully qualified path name
   %~d1        - expands %1 to a drive letter only
   %~p1        - expands %1 to a path only
   %~n1        - expands %1 to a file name only
   %~x1        - expands %1 to a file extension only
   %~s1        - expanded path contains short names only
   %~a1        - expands %1 to file attributes
   %~t1        - expands %1 to date/time of file
   %~z1        - expands %1 to size of file
   %~$PATH:1   - searches the directories listed in the PATH
                  environment variable and expands %1 to the fully
                  qualified name of the first one found.  If the
                  environment variable name is not defined or the
                  file is not found by the search, then this
                  modifier expands to the empty string
可以组合修改器以获得复合结果:

  %~dp1       - expands %1 to a drive letter and path only
   %~nx1       - expands %1 to a file name and extension only
   %~dp$PATH:1 - searches the directories listed in the PATH
                  environment variable for %1 and expands to the
                  drive letter and path of the first one found.
   %~ftza1     - expands %1 to a DIR like output line

您可以使用扩展到当前用户配置文件的
%USERPROFILE%
,如
C:\Users\jackjameshoward\Desktop\Folder
…您可以使用扩展到当前用户配置文件的
%USERPROFILE%
,像
C:\Users\jakemeshoward\Desktop\Folder
…我用下面的代码创建了.bat,它似乎完成了这个技巧
start%windir%\system32\cmd.exe/k cd“Folder”
我用下面的代码创建了.bat,它似乎完成了这个技巧
start%windir%\system32\cmd.exe/k cd“Folder”