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

Windows环境下批量检测删除对应文件存在的.url后缀文件

批量清理多余的.url文件方案

方案1:Batch 脚本

  • 功能:递归遍历指定目录下所有子文件夹,自动检查每个.url文件是否存在对应的同名常规文件(去掉.url后缀),存在则删除该.url文件
  • 代码:
@echo off
set "target_dir=你要处理的根目录路径"
for /r "%target_dir%" %%f in (*.url) do (
    set "base_file=%%~dpnf"
    if exist "!base_file!" (
        echo 删除:"%%f"
        del "%%f"
    )
)
echo 清理完成
pause
  • 使用步骤:
    • 把你要处理的根目录路径替换成实际路径,比如D:\我的文件
    • 复制代码保存成.bat后缀的文件,双击运行
    • 运行时会先显示要删除的文件,确认后自动执行删除

方案2:PowerShell 脚本

  • 功能:和Batch脚本逻辑一致,用PowerShell实现更灵活的文件检查与操作
  • 代码:
$targetDir = "你要处理的根目录路径"
$urlFiles = Get-ChildItem -Path $targetDir -Filter "*.url" -Recurse
foreach ($urlFile in $urlFiles) {
    $baseFilePath = $urlFile.FullName -replace '\.url$', ''
    if (Test-Path -Path $baseFilePath) {
        Write-Host "删除:$($urlFile.FullName)"
        Remove-Item -Path $urlFile.FullName -Force
    }
}
Write-Host "清理完成"
  • 使用步骤:
    • 替换你要处理的根目录路径为实际目录
    • 保存成.ps1后缀的文件,右键选择「用PowerShell运行」
    • 如果提示权限不足,先打开PowerShell执行Set-ExecutionPolicy RemoteSigned,按提示输入Y确认后再运行脚本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 07:20:53