You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编写批处理文件查找并删除嵌套的!img子目录

解决嵌套!img目录的问题

一、批处理脚本实现

以下批处理脚本可查找所有包含!img\!img的路径,并删除第二层及后续的!img目录(及其所有子内容):

@echo off
setlocal enabledelayedexpansion
set "target=!img\!img"

:: 递归遍历所有名为!img的目录
for /r %%d in (!img) do (
    set "dirpath=%%~fd"
    :: 检查路径是否包含嵌套的!img\!img
    echo !dirpath! | findstr /i /c:"!target!" >nul
    if not errorlevel 1 (
        :: 确认当前!img的父目录也是!img(即属于嵌套层级)
        for %%p in ("!dirpath!\..") do (
            set "parent=%%~fp"
            echo !parent! | findstr /i /c:"!img$" >nul
            if not errorlevel 1 (
                echo 正在删除: !dirpath!
                rd /s /q "!dirpath!"
            )
        )
    )
)
endlocal
echo 处理完成
pause

脚本说明:

  • setlocal enabledelayedexpansion:开启延迟变量扩展,避免路径中感叹号的解析冲突
  • for /r %%d in (!img):递归扫描所有名为!img的目录
  • 通过findstr筛选出包含!img\!img的嵌套路径
  • 验证父目录为!img后,用rd /s /q无提示递归删除目标目录

二、查找嵌套!img路径的工具

  1. PowerShell命令:快速列出所有嵌套的!img目录:
Get-ChildItem -Recurse -Directory -Name "!img" | Where-Object { $_ -match '!img\\!img' }
  1. Everything工具:在搜索框输入 path:!img\!img,可实时定位所有包含该嵌套路径的目录,搜索效率极高。

内容的提问来源于stack exchange,提问作者user704270

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 13:03:17