Creating Symbolic and Hard Links with a Batch File

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Posts: 8
Joined: 06 Nov 2012 10:45

Re: Simple (?) DelayedExpansion / String Problems [NOOB]

#16 Post by soad1789 » 07 Nov 2012 10:41

Good to know. Just ran the final version of the batch on a sample of the files, and it worked fantastic!

:!: However, if anyone is looking at how to batch the creation of symbolic- or hard- links, note that you need Administrative rights in your batch script. I found this block of code, pasted at the top of my file, to prompt for Admin rights before the code runs. Doing it manually from the context menu > 'Run as administrator' was giving the batch file problems, so this method was much more effective.

I also made an error in my last version that I posted here, on the code for the actual link generation:

Code: Select all

MKLINK "%dst%\!var2!%%~nxA" "%%A"

The last version was creating all the links in the working directory of the batch :shock: , this one will correctly place the symbolic link in the mirrored directory, also accounting for subdirectories.

Thank you thank you guys for the help! Hopefully this might help any other poor soul who decides to resort to a batch file to automate symlink creation!

P.S. If you want to create hard- and soft- links WITHOUT a batch, check this out.

Posts: 16
Joined: 29 Jan 2013 08:17

Re: Creating Symbolic and Hard Links with a Batch File

#17 Post by nickodemos » 25 Sep 2017 14:42

I know I am posting to an old thread but the script that foxidrive posted worked well for me except for one thing.

Is it possible to have it rename FILESINLOOP.txt to FILESINLOOPOLD.txt and when done creating FILESINLOOP.txt it scans FILESINLOOPOLD.txt for dupes and removes them from FILESINLOOP.txt. Then makes the links?

The idea being is that I want to be able to manipulate the files in the new directory but not have to put up with removing old files many times after each copy.


Run batch file. These files are moved and now in FILESINLOOP.txt.


I delete A.txt. I move B.txt to \b\B.txt. I rename C.txt to Z.txt. SO now the directory looks like:


If I run the batch file again it just carries over A,B,C.txt again and now I need to delete them since I already worked on them.

Ideally it would be nice if their could be times FILESINLOOP.txt and all are checked and then any FILESINLOOP.txt over 14 days could be deleted.

Was I clear in saying this?

Post Reply