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] )
未经博主允许,禁止直接转载本博客任何内容(可以在文章中添加链接,禁止原文照搬),如需直接原文转载对应文章,请在该文章中留言联系博主,谢谢!!