mklink Junction Point Link cannot create file

1.8k views Asked by At

I'm trying to create a .BAT file where it will create App Links and Web Links using MkLink but I can't seem to get it running.

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

What should I change, or am I missing? I am new to create .bat file and using mklink.

1

There are 1 answers

0
JosefZ On BEST ANSWER

Read mklink description or 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.

Both errors are related to the Link part of commands, see next example:

==> 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]

==>

Use echo ON to see exactly what happens.

BTW, the %~dp0 and %CD% directories could differ:

  • %~dp0 = folder where a script resides
  • %CD%  = current directory