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

时间:2016-04-08 10:28:28

标签: windows batch-file cmd

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

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

C:\Users\"user"\Desktop

我想在Folder

中打开cmd
C:\Users\"user"\Desktop\Folder

但我不希望它依赖于完整的路径。我希望能够将exe和文件夹一起移动到另一个位置,它仍然可以工作。所以我希望exe在当前路径+ \ Folder

中启动cmd.exe
%windir%\system32\cmd.exe  +  \Folder

2 个答案:

答案 0 :(得分:0)

你可以把" cd文件夹"在蝙蝠文件中。

exe取决于你用它来创建它,并且不了解快捷方式。

此外,您可以在bat文件中使用%cd%来获取当前路径。

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

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

答案 1 :(得分:0)

有关文件名/路径的列表,请参阅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