Creating Symbolic and Hard Links with a Batch File
Posted: 06 Nov 2012 10:54
I'm trying to write a batch file that will take the files in folder X (has subdirectories) and create absolute symbolic links with the same filename and directory structure in folder Y (I want ACTUAL folders, only files as symlinks).
I already have this so far, but I'm stuck because I don't understand the delayed expansion premise... I'm pretty sure it's relevant here, but even with it on I can't seem to get %%G into a variable to perform string functions on it (another thing that confuses me a lot in batch... how do I trim the filepath to just a filename here?).
Any help would be greatly appreciated, seems like you guys know what you're doing!
Thanks in advance for any advice / help!
EDIT: Changed the topic title to make this easier to find for others with similar goals.
I already have this so far, but I'm stuck because I don't understand the delayed expansion premise... I'm pretty sure it's relevant here, but even with it on I can't seem to get %%G into a variable to perform string functions on it (another thing that confuses me a lot in batch... how do I trim the filepath to just a filename here?).
Any help would be greatly appreciated, seems like you guys know what you're doing!
Code: Select all
@ECHO OFF
SETLOCAL EnableDelayedExpansion
IF EXIST "FILESINLOOP.txt" DEL "FILESINLOOP.txt"
SET SRC="X"
SET DST="Y"
PAUSE
FOR /F "USEBACKQ DELIMS=|" %%G IN (`dir /B /S /A:-D "X"`) DO (
ECHO %%G >> FILESINLOOP.txt
SET CURFILE=%%G
ECHO %CURFILE%
MKLINK "Y\[trimmed curfile path>filename]" %%G
)
PAUSE
Thanks in advance for any advice / help!
EDIT: Changed the topic title to make this easier to find for others with similar goals.