Andy Alvarez
Andy Alvarez

Reputation: 51

Batch File to Create Multiple Symbolic Links

I've looked around a little bit and have tried different things but haven't had any luck. I'm not very good with batch when it comes to "for loops" but I think this is exactly what I need to accomplish my goal.

Ok, so I have 35 symbolic links to create. The thing is, there will be more of these that I will have to create starting very soon, and they will usually be in the dozens, so a script is the way to go here for sure.

My goal:
I have a folder: F:\Browser Downloads\Ortho4XP\Tiles\Cuba\
This folder includes 35 sub-folders (I need all the contents of those folders in the symbolic link) Example sub-folders:

zOrtho4XP_+20-074
zOrtho4XP_+25-077
zOrtho4XP_+22-073
zOrtho4XP_+23-075
zOrtho4XP_+23-079

... and so on

I need a symbolic link to be created for each of those sub-folders above in the following directory:

E:\X Plane 11\X-Plane 11\Custom Scenery\Ortho\Cuba

How would I script something like this?

I deeply appreciate any help with this. Any ideas are welcome!

Upvotes: 1

Views: 4244

Answers (1)

michael_heath
michael_heath

Reputation: 5372

@echo off
setlocal

set "target=F:\Browser Downloads\Ortho4XP\Tiles\Cuba"
set "destination=E:\X Plane 11\X-Plane 11\Custom Scenery\Ortho\Cuba"

for /d %%A in ("%target%\*") do mklink /d "%destination%\%%~nxA" "%%~A"

The modifier of nx in %%~nxA gets the folder name. See for /? about modifiers.

mklink requires Admin privileges.

Upvotes: 1

Related Questions