bat cmd 遍历符号链接,symlink
bat cmd 遍历符号链接,symlink
参考链接:batch file (windows cmd.exe) test if a file is a link - Stack Overflow
@echo off set SearchTarget=%~dp0 for /f "tokens=*" %%a in ('dir /s /b /a:l %SearchTarget% 2^>nul') do ( echo %%a if exist "%%a" ( rmdir "%%a" ) ) pause
注意:这个遍历包括子目录, rmdir 并不会删除真正的目录,只会删除链接本身
参考的例子添加了很多细节:
@echo off setlocal EnableDelayedExpansion set ScriptPath=%~dp0 cd /d "%ScriptPath%" set "r=%__CD__%" set SearchTarget=SomePath for /f "tokens=*" %%a in ('dir /s /b /a:l %SearchTarget% 2^>nul') do ( set "FullPath=%%a" set "LocalPath=!:%r%=!" rem local -> [absolute] echo(!FullPath:%r%=! -^> [%%a] )