From d6a9d9a82b85737907aff9d57b94b15621178137 Mon Sep 17 00:00:00 2001 From: InvalidArgument3 Date: Sat, 28 Sep 2024 21:13:21 -0500 Subject: [PATCH] Update remove-semods-symlinks.bat --- remove-semods-symlinks.bat | 80 ++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 24 deletions(-) diff --git a/remove-semods-symlinks.bat b/remove-semods-symlinks.bat index 53d9b87..b2b98a8 100644 --- a/remove-semods-symlinks.bat +++ b/remove-semods-symlinks.bat @@ -1,39 +1,71 @@ @echo off setlocal enabledelayedexpansion -:: Check if the script is running with administrative privileges -NET SESSION >NUL 2>&1 -if %ERRORLEVEL% NEQ 0 ( - echo Please run this script as administrator! +REM Check if the script is running as administrator +>nul 2>&1 "%SystemRoot%\system32\cacls.exe" "%SystemRoot%\system32\config\system" +if '%errorlevel%' NEQ '0' ( + echo. + echo ==================================================== + echo This script must be run as an administrator to remove symlinks! + echo Right-click the script and select "Run as administrator". + echo ==================================================== + echo. pause - exit /b 1 + exit /b ) -set "targetDir=%APPDATA%\SpaceEngineers\Mods" -set "desktopDir=%USERPROFILE%\Desktop\SpaceEngineersModsBackup" +REM Define the root Space Engineers mod directory +set modRootDir="%APPDATA%\SpaceEngineers\Mods" -:: Creating desktop directory if it doesn't exist -if not exist "%desktopDir%" ( - mkdir "%desktopDir%" +REM Check if the mod directory exists +if not exist !modRootDir! ( + echo Mod directory does not exist: !modRootDir! + echo Please ensure that the Space Engineers game has created mod directories. + pause + exit /b ) -:: Copying non-symbolic link folders to the desktop -for /d %%i in ("%targetDir%\*") do ( - set "folderName=%%~nxi" - fsutil reparsepoint query "%%i" > nul 2>&1 - if errorlevel 1 ( - robocopy "%%i" "%desktopDir%\!folderName!" /E /NFL /NDL /NJH /NJS /nc /ns /np - ) +REM Change to the mod directory +cd /d "!modRootDir!" + +REM List only symbolic links in the mod directory +echo. +echo Searching for symbolic links in: !modRootDir! +set foundSymlink=false +for /f "tokens=*" %%l in ('dir /AL /B') do ( + set foundSymlink=true + echo Found symlink: %%l +) + +REM Check if any symbolic links were found +if "!foundSymlink!"=="false" ( + echo No symbolic links found in: !modRootDir! + pause + exit /b +) + +REM Prompt the user for confirmation once to delete all symbolic links +set /p confirmDelete="Do you want to delete all symlinks in this directory? [Y/N]: " +if /i "!confirmDelete!" NEQ "Y" ( + echo Operation canceled. No symlinks were removed. + pause + exit /b ) -:: Removing symbolic links from the mod folder -for /d %%i in ("%targetDir%\*") do ( - set "folderName=%%~nxi" - fsutil reparsepoint query "%%i" > nul 2>&1 - if not errorlevel 1 ( - rmdir /s /q "%%i" - echo Removed symlink in "%%i" +REM Remove all symlinks in the mod directory +echo. +echo Deleting all symbolic links in: !modRootDir! +for /f "tokens=*" %%l in ('dir /AL /B') do ( + echo Removing symlink: %%l + rmdir "%%l" + if !errorlevel! == 0 ( + echo Successfully removed symlink: %%l + ) else ( + echo Failed to remove symlink: %%l. Check permissions or path issues. ) ) +REM Completion message +echo. +echo All symbolic links have been removed from: !modRootDir! pause