我正在尝试创建一个.BAT文件,它将使用MkLink创建App Links和Web Links但我似乎无法让它运行。
@echo off
SET LINK_APPROOT=C:\Users\Intern\Desktop\debugprojects\GeneratedAppServer
SET LINK_WEBROOT=C:\Users\Intern\Desktop\debugprojects\GeneratedWebServer
SET TARGET_ROOT=C:\inetpub\wwwroot
SET WWWROOT_DIR=C:\inetpub\wwwroot
SET CURRENT_DIR=%~dp0
REM Creating App links
mklink /j %LINK_APPROOT%\GeneratedAppServer\commandline %TARGET_ROOT%\App\App_Code\commandline
mklink /j %LINK_APPROOT%\GeneratedAppServer\dbaccess %TARGET_ROOT%\App\App_Code\dbaccess
mklink /j %LINK_APPROOT%\GeneratedAppServer\entitydef %TARGET_ROOT%\App\App_Code\entitydef
mklink /j %LINK_APPROOT%\GeneratedAppServer\hub %TARGET_ROOT%\App\App_Code\hub
mklink /j %LINK_APPROOT%\GeneratedAppServer\lib %TARGET_ROOT%\App\App_Code\lib
mklink /j %LINK_APPROOT%\GeneratedAppServer\service %TARGET_ROOT%\App\App_Code\service
REM Creating Web links
mklink /j %LINK_WEBROOT%\GeneratedWebServer\entitydef %TARGET_ROOT%\Web\App_Code\entitydef
mklink /j %LINK_WEBROOT%\GeneratedWebServer\hub %TARGET_ROOT%\Web\App_Code\hub
mklink /j %LINK_WEBROOT%\GeneratedWebServer\lib %TARGET_ROOT%\Web\App_Code\lib
mklink /j %LINK_WEBROOT%\GeneratedWebServer\View_Code %TARGET_ROOT%\Web\App_Code\View_Code
mklink /j %LINK_WEBROOT%\GeneratedWebServer\web\App_Pages %TARGET_ROOT%\Web\App_Pages
mklink /j %LINK_WEBROOT%\GeneratedWebServer\web\Images %TARGET_ROOT%\Web\Images
mklink /j %LINK_WEBROOT%\GeneratedWebServer\web\Scripts %TARGET_ROOT%\Web\Scripts
mklink /j %LINK_WEBROOT%\GeneratedWebServer\web\WS %TARGET_ROOT%\Web\WS
pause
我应该改变什么,或者我错过了什么?我是新手创建.bat文件并使用mklink。
答案 0 :(得分:1)
阅读mklink
description或mklink /?
:
==> mklink /?
Creates a symbolic link.
MKLINK [[/D] | [/H] | [/J]] Link Target
/D Creates a directory symbolic link. Default is a file
symbolic link.
/H Creates a hard link instead of a symbolic link.
/J Creates a Directory Junction.
Link specifies the new symbolic link name.
Target specifies the path (relative or absolute) that the new link refers to.
这两个错误都与命令的Link
部分有关,请参阅下一个示例:
==> dir d:\bat\files\bub*| findstr /I "bub"
23.11.2015 17:57 <DIR> bubu
==> mklink /J "D:\bat\files\bubu" "D:\test\a folder path"
Cannot create a file when that file already exists.
==> mklink /J "D:\bat\filesNoFolder\bubu" "D:\test\a folder path"
The system cannot find the path specified.
==> mklink /J "D:\bat\files\bubux" "D:\test\a folder path\even if not exists"
Junction created for D:\bat\files\bubux <<===>> D:\test\a folder path\even if not exists
==> dir d:\bat\files\bub*| findstr /I "bub"
23.11.2015 17:57 <DIR> bubu
27.12.2016 10:08 <JUNCTION> bubux [D:\test\a folder path\even if not exists]
==>
使用echo ON
查看具体情况。
BTW,%~dp0
和%CD%
目录可能有所不同:
%~dp0
=脚本所在的文件夹%CD%
=当前目录