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

如何删除Tesseract中无对应.box文件的.gt.txt与.tif文件

删除无对应.box文件的.gt.txt与.tif文件

适用于Linux/macOS的Shell脚本

遍历所有.gt.txt文件,检查对应的.box文件是否存在,若不存在则删除该.gt.txt及其配对的.tif文件:

# 遍历当前目录下的所有.gt.txt文件
for f in *.gt.txt; do
    # 提取基础文件名(去掉.gt.txt后缀)
    base="${f%.gt.txt}"
    # 检查对应的.box文件是否存在
    if [ ! -f "$base.box" ]; then
        # 删除无.box配对的.gt.txt和.tif文件
        rm "$f" "$base.tif"
        echo "已清理:$f 和 $base.tif"
    fi
done

如果需要递归处理子目录,改用find命令:

find . -name "*.gt.txt" -type f | while read -r gtfile; do
    base="${gtfile%.gt.txt}"
    boxfile="$base.box"
    tiffile="$base.tif"
    if [ ! -f "$boxfile" ]; then
        rm "$gtfile" "$tiffile"
        echo "已清理:$gtfile, $tiffile"
    fi
done

适用于Windows的PowerShell脚本

Windows环境下用以下PowerShell命令批量处理:

Get-ChildItem -Filter *.gt.txt -Recurse | ForEach-Object {
    $base = $_.BaseName -replace '\.gt$', ''
    $boxPath = Join-Path $_.DirectoryName "$base.box"
    $tifPath = Join-Path $_.DirectoryName "$base.tif"
    
    if (-not (Test-Path $boxPath)) {
        Remove-Item $_ -Force
        if (Test-Path $tifPath) {
            Remove-Item $tifPath -Force
        }
        Write-Host "已删除:$($_.FullName) 和 $tifPath"
    }
}

内容的提问来源于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:52:10