:: Sample TweakSymbolicLinksPreview.bat file :: DISCLAIMER: Using this script, or any of this advice may turn your system into a puddle of silicon :: or cause a complete loss of all data. Use at your own risk! :: Author: Jay Ohman, Ohman Automation Corp. :: Rev: 10/30/2011 :: Purpose: Development script for previewing junction points and symbolic links to be changed. :: Reference: http://www.ohmancorp.com/RefWin-Win2008R2-AltProfilesFixJuctions.asp @echo off setlocal echo ----------------------------- BEGIN ----------------------------- echo Fetching all junction/symlink references from entire C: drive.... C: set FindBadDir=C:\Users set CorrectDir=C:\Profiles :: ** if desired, try a simpler directory first set BeginDir="\" :: set BeginDir="\Profiles" :: set BeginDir="\Profiles\All Users" cd %BeginDir% :: ** go fetch from the current directory and all sub-directories all entries with "reparse point" attribute :: ** split each line on the less-than "<" and greater-than ">" characters, call sub :x1 for /f "tokens=1-3 delims=><" %%a in ('dir /al /s') do call :x1 "%%a" "%%b" "%%c" goto :finish :x1 :: ** process each entry :: echo info: %1, %2, %3 :: ** looking for a change in sub-directory, process in sub :x2 echo %~1 | findstr /i /r /c:"Directory of C:" > NUL && call :x2 %1 :: ** looking for entries to be changed (skip all other junction/symlink entries), process in sub :x3 echo %~3 | findstr /i /r /c:"%FindBadDir:\=\\%" > NUL && call :x3 %3 :: ** showing how special characters need to be escaped :: echo %~3 | findstr /i /r /c:"C:\\Users" > NUL && call :x3 %3 goto :EOF :x2 :: ** extract the current sub-directory name :: echo a%1a set xLin=%~1 :: ** chop off the first part of the line, leaving the directory name set xCurDir=%xLin: Directory of C=C% if NOT "%xCurDir%"=="C:\" set xCurDir=%xCurDir%\ echo Checking directory: %xCurDir% goto :EOF :x3 :: ** process the junction/symlink entry :: echo b%1b set xLin=%~1 :: ** chop off leading spaces set xParseLin=%xLin: =% :: echo b%xParseLin%b :: ** split the line on the square-bracket characters, call sub :x4 for /f "tokens=1-2 delims=][" %%i in ('echo %xParseLin%') do call :x4 "%%i" "%%j" set xLin= set xParseLin= goto :EOF :x4 :: ** extract the directory name references, for fixing the junction/symlink entry :: ** use # chars to dump the trailing space set xTmp=%~1### :: echo %xTmp% :: ** set the junctions/symlink entry name set xFPName=%xCurDir%%xTmp: ###=% :: echo %xFPName% :: ** the destination of the bad junction/symlink set xFPDestBad=%~2 :: echo %xFPDestBad% :: ** this next line worked, but better to use variable and add the "C:" (unable to figure how to escape the ":") :: set xFPDestNew=%xFPDestBad:\Users=\Profiles% Setlocal EnableDelayedExpansion :: ** replace the bad junction/symlink text with the new bad junction/symlink text set xFPDestNew=!xFPDestBad:%FindBadDir%=%CorrectDir%! Endlocal&Set xFPDestNew=%xFPDestNew% :: echo %xFPDestNew% echo Old: %xFPName% --^> %xFPDestBad% echo New: %xFPName% --^> %xFPDestNew% set xTmp= set xFPName= set xFPDestBad= set xFPDestNew= goto :EOF :finish set FindBadDir= set CorrectDir= set BeginDir= echo ------------------------------ END ------------------------------