不知道这是不好的风格,但我在这里问这个问题,因为我在其他地方找不到答案,然后我自己找出一个解决scheme。 我有兴趣看到别人的解决scheme,但几天后,我会张贴我自己的。
在我的具体情况,我在Windows 7上运行,但我会对其他/旧版本的Windows的答案感兴趣。 我意识到一个答案是“安装一个版本的Unix发现,然后解决Unix ”,但我想要一个更“原生”的解决scheme。
编辑2012-07-17:澄清:通过“自动”我理想的意思是我可以作为一个脚本的一部分运行,而不是一个button的所有工作的GUI工具,因为我会想做这个无人看pipe。
有点迟来,但这是我自己的回答我的问题。 它基本上和Unix上通常的一样:find所有的链接,然后对破坏的链接进行操作; 它只是不够简洁。 下面的脚本在删除了一些关于它们的信息之后删除了损坏的符号链接。
@echo off rem Grab the list of directories to scan, before we "pushd to dir containing this script", rem so that we can have the default be "dir from which we ran this script". setlocal if x%CD%==x (echo Command Extensions must be enabled. && goto :eof) set ORIGINAL_DIR=%CD% pushd %~dp0 set DIRS_TO_CHECK=%* if x%DIRS_TO_CHECK%==x ( set DIRS_TO_CHECK=. ) rem Find all the files which are both links (/al) and directories (/ad). rem (We use "delims=" in case any paths have a space; space is a delim by default.) rem If not, delete it (and assume something else will fix it later :-). echo Deleting broken symlinks ... echo. for %%D in (%ORIGINAL_DIR%\%DIRS_TO_CHECK%) do ( echo Checking %%D echo. pushd %%D if errorlevel 1 ( echo Cannot find "%%D" echo. goto :Next_Dir ) rem Clean up broken directory links. for /f "usebackq delims=" %%L in (`dir /adl /b`) do ( rem Check the directory link works. rem Redirecting to nul just to hide "The system cannot find the file specified." message. pushd "%%L" >nul 2>&1 if errorlevel 1 ( echo Deleting broken directory symlink "%%L". rem First dump out some info on the link, before we delete it. rem I'd rather a more human-readable form, but don't know how to get that. fsutil reparsepoint query "%%L" rmdir "%%L" echo. ) else ( popd ) ) rem Clean up broken file (non-directory) links. for /f "usebackq delims=" %%L in (`dir /a-dl /b`) do ( rem Check the file link works. rem Redirecting to nul just to hide "The system cannot find the file specified." message. copy "%%L" nul >nul 2>&1 if errorlevel 1 ( echo Deleting broken file symlink "%%L". rem First dump out some info on the link, before we delete it. rem I'd rather a more human-readable form, but don't know how to get that. fsutil reparsepoint query "%%L" rm "%%L" echo. ) else ( popd ) ) popd :Next_Dir rem Putting a label on the line immediately before a ')' causes a batch file parse error, hence this comment. ) echo Deleting broken symlinks ... done. :Finally popd
以下工具可能会帮助您查找和删除Windows中的符号链接
您也可以尝试一个名为SageLinks的开源实用程序,它显示并检查Windows NTFS联结,符号链接甚至快捷方式。