AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 408192
Accepted
HughG
HughG
Asked: 2012-07-17 07:58:19 +0800 CST2012-07-17 07:58:19 +0800 CST 2012-07-17 07:58:19 +0800 CST

如何在 Windows 上自动查找损坏的符号链接?

  • 772

不确定这是否是糟糕的风格,但我在这里问这个问题是因为我在别处找不到答案,然后我自己制定了一个解决方案。我很想看看其他人的解决方案,但几天后我会发布自己的解决方案。

在我的具体情况下,我在 Windows 7 上运行,但我对其他/旧版本 Windows 的答案感兴趣。我意识到一个答案是“安装一个 Unix 版本,然后解决 Unix ”,但我想要一个更“本地”的解决方案。

编辑 2012-07-17:澄清:“自动”我理想的意思是我可以作为脚本的一部分运行,而不是一个 GUI 工具,它可以在按下按钮时完成所有工作,因为我想做这个无人值守。

windows symbolic-link
  • 4 4 个回答
  • 7540 Views

4 个回答

  • Voted
  1. Best Answer
    HughG
    2012-09-18T00:58:51+08:002012-09-18T00:58:51+08:00

    有点迟了,但这是我自己对我的问题的回答。它基本上与 Unix 上常用的方法相同:找到所有链接,然后对损坏的链接采取行动;它只是不那么简洁。下面的脚本在转储了一些关于它们的信息后删除了损坏的符号链接。

    @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
    
    • 4
  2. Abhijeet Kasurde
    2012-07-17T09:09:57+08:002012-07-17T09:09:57+08:00

    以下工具可以帮助您在 Windows 中查找和删除符号链接

    1. 连接链路魔法
    2. 磁盘连接
    • 3
  3. Nikolay Raspopov
    2015-09-27T00:07:22+08:002015-09-27T00:07:22+08:00

    您还可以尝试一个名为SageLinks的开源实用程序,它显示并检查 Windows NTFS 连接、符号链接甚至快捷方式。

    • 2
  4. mosh
    2018-12-06T19:45:16+08:002018-12-06T19:45:16+08:00

    使用 cygwin64 (find, xargs, sh, ls)(在 win7 上测试死的 ntfs 硬链接)

    c:\>   find ./ -type l |  xargs -I % sh -c "ls % > /dev/null 2>&1 || echo %" 
    

    注意:test -e 不能像预期的那样使用死的 ntfs 硬链接。

    • 0

相关问题

  • 知道任何适用于 Windows 的快速可编写脚本的 ftp 客户端吗?[关闭]

  • 如果 Windows 服务崩溃,如何自动重新启动它?

  • 无法安排任务(访问被拒绝)

  • 物理机重启时自动重启虚拟机(VMWare)

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve