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

如何查找并删除空.box文件及其关联的Tesseract训练文件?

解决方案:删除空.box文件及关联文件

当然可以实现这个需求,以下是不同操作系统下的具体实现方法:

Linux/macOS 环境

用一行shell命令即可完成批量处理:

find . -type f -name "*.box" -empty | while read boxfile; do
    prefix="${boxfile%.box}"
    rm -f "$boxfile" "${prefix}.gt.txt" "${prefix}.tif"
done

命令说明:

  • find . -type f -name "*.box" -empty:检索当前目录及子目录下所有大小为0的.box空文件
  • while read boxfile:逐个处理找到的空.box文件
  • prefix="${boxfile%.box}":提取文件的基础名称(去掉.box后缀)
  • rm -f:强制删除目标文件,即使关联的.gt.txt或.tif文件不存在也不会抛出错误

Windows 环境

方法1:批处理脚本(保存为clean_empty_box.bat)

@echo off
setlocal enabledelayedexpansion

for %%f in (*.box) do (
    if %%~zf equ 0 (
        set "prefix=%%~nf"
        del "%%f"
        del "!prefix!.gt.txt"
        del "!prefix!.tif"
    )
)

endlocal

方法2:PowerShell 命令

直接在PowerShell窗口中执行:

Get-ChildItem -Filter *.box | Where-Object { $_.Length -eq 0 } | ForEach-Object {
    $prefix = $_.BaseName
    Remove-Item $_.FullName -Force
    Remove-Item "$prefix.gt.txt" -Force -ErrorAction SilentlyContinue
    Remove-Item "$prefix.tif" -Force -ErrorAction SilentlyContinue
}

Windows 方案说明:

  • 两种方法都会遍历当前目录下的.box文件,筛选出空文件后,删除该文件及其同名前缀的.gt.txt和.tif文件
  • -ErrorAction SilentlyContinue(PowerShell)和批处理的del命令默认行为,都会忽略“文件不存在”的错误,避免中断批量处理

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 16:22:15