Reputation: 6157
I have d:\folder1 and e:\folder2 What I want to do is create a simlink for each file/folder/ from d:\folder1 in e:\folder2. Recursive if possible
What I tried so far is
for %f in (d:\folder1\*) do mklink /d %~dp0\%f
It only created some links for files which seem to not work
Does anyone has experience with this?
Upvotes: 0
Views: 3476
Reputation: 7117
Well if you're only using one % for your variables, I'd assume you're doing this from cmd prompt. %~dp0
won't resolve from the cmd prompt. You have to put that in a batch file and double the %'s. Since you're using the /d
switch for mklink
That implies that you want to create a directory symbolic link. If that's the case, use:
For /d %%f in (d:\folder1\*) do mklink /d "%%~df\%%~nflink" "%~dp0%%~nf"
Notice there is no backslash. %%~dp0 already includes it.
If you need to create simlinks to files as well, use
For /f "tokens=*" %%f in ('dir /s /b /a-d "d:\folder1"') do mklink "%%~dpnflink" "%~dp0%%~nxf"
Upvotes: 2