Skip to content

Instantly share code, notes, and snippets.

@ahmedrowaihi
Created October 26, 2023 12:46
Show Gist options
  • Save ahmedrowaihi/a9b5de1b521d307d78246d4087fc8cf9 to your computer and use it in GitHub Desktop.
Save ahmedrowaihi/a9b5de1b521d307d78246d4087fc8cf9 to your computer and use it in GitHub Desktop.
@echo off
setlocal enabledelayedexpansion
rem Define arrays for paths and targets
set "Dirs[0]=PATH_TO_IMAGE_DIRECTORY"
set "Dirs[1]=PATH_TO_LOGOS_DIRECTORY"
set "Dirs[2]=PATH_TO_SVG_DIRECTORY"
set "Dirs[3]=PATH_TO_IMG_DIRECTORY"
set "Targets[0]=TAEGET_IMAGE_DIRECTORY"
set "Targets[1]=TAEGET_LOGOS_DIRECTORY"
set "Targets[2]=TAEGET_SVG_DIRECTORY"
set "Targets[3]=TAEGET_IMG_DIRECTORY"
rem Delete directories/symbolic links, prevent git branch switching errors
for /l %%i in (0,1,3) do (
for %%F in ("!Dirs[%%i]!\.") do set "LastFolder=%%~nxF"
call :DeleteFolder "!Dirs[%%i]!" "!Targets[%%i]!" "!LastFolder!"
)
goto :eof
:DeleteFolder
rem Safe delete directory/symbolic link
rmdir /s /q "%~1" 2>nul
if errorlevel 1 (
echo Could not delete %~3 directory
goto :eof
) else (
rem Create symbolic link
mklink /d "%~1" "%~2" >nul
if errorlevel 1 (
echo Could not create symbolic link for %~3 directory
goto :eof
) else (
echo Successfully linked %~3 directory
)
)
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment