2016-12-27 128 views
-1

我試圖創建一個.BAT文件,它將使用MkLink創建應用程序鏈接和Web鏈接,但我似乎無法使其運行。mklink連接點鏈接無法創建文件

enter image description here

@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。

回答

1

mklink descriptionmklink /?

==> 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,看看到底發生了什麼。

順便說一句,該%~dp0%CD%目錄可以不同:

  • %~dp0 =文件夾中的腳本駐留
  • %CD%  =當前目錄