I have been trying to make symbolic links from multiple sources.
I have a reg.txt
file in the new
directory as well as the sort.bat.
the reg.txt
:-
redcar1=123456 greencar2=345678
In directory called vehicles
with sub directories of 'reg_numbers' ie:- 123456
,
within that directory I have a sub directory called keys
, or key
, with a *.txt
file.
I want to symbolic link all the 'reg_numbers' (parsing the reg.txt
- changing the folder name in the process) directories into the new
directory the sort.bat file is in, and all the keys
or Key
directory files (*.txt), into a common keys
directory in the new
folder
so say:-
D:\vehicles\123456\keys\this.txt
D:\vehicles\345678\key\that.txt
symbolic linked
e:\new\redcar1\
e:\new\greencar2\
e:\new\keys\this.txt
e:\new\keys\that.txt
sort.bat is in the new folder.
@echo off
setlocal EnableDelayedExpansion
set NEWPATH=%~dp0
set OLDPATH=d:\vehicles
for /f %%d in ('dir /b %NEWPATH%\keys') do (
if not "%%d"=="not.txt" del /Q "%NEWPATH%Keys\%%d" ::clean out files
)
for /f "tokens=1,2 delims==" %%a in (reg.txt) do (
rmdir /Q "%NEWPATH%%%a" ::clean out dir
mklink /D %NEWPATH%"%%a" %OLDPATH%\"%%b"
for /f %%c in ('dir /b %OLDPATH%\%%b\keys' ) do (
mklink %NEWPATH%Keys\"%%c" %OLDPATH%\"%%b"\"%%c"
)
)
It's probably a mess but it works for nearly everything but I cannot get the that.txt
from key
folder.