使用tiffcp批量修改文件夹内所有TIFF文件的rows per strip参数
批量修改TIFF文件rows per strip参数方案
以下所有方案均依赖libtiff工具包的
tiffcp命令,使用前请确认已正确安装并添加到系统环境变量中。
Linux/macOS 环境
方案1:生成新文件(保留原文件,推荐)
将处理后的文件统一存放在当前目录的output文件夹下,保持和原目录完全一致的结构:
- 先创建输出根目录:
mkdir -p output - 执行批量处理命令:
find . -type f \( -iname "*.tif" -o -iname "*.tiff" \) -exec sh -c ' for file do outpath="output/${file#./}" mkdir -p "$(dirname "$outpath")" tiffcp -r 20 "$file" "$outpath" done ' sh {} +
方案2:直接覆盖原文件
操作前请务必备份所有原TIFF文件,避免数据丢失
find . -type f \( -iname "*.tif" -o -iname "*.tiff" \) -exec sh -c ' for file do tiffcp -r 20 "$file" "$file.tmp" && mv "$file.tmp" "$file" done ' sh {} +
处理逻辑为先生成临时文件,确认处理成功后再替换原文件,避免处理过程中断导致原文件损坏。
Windows 环境
方案1:PowerShell生成新文件(推荐)
在目标根目录下右键选择「在此处打开PowerShell窗口」,执行以下命令,处理后的文件会存放在同级output目录下:
New-Item -ItemType Directory -Name output -Force | Out-Null Get-ChildItem -Path . -Recurse -Include *.tif,*.tiff -File | ForEach-Object { $outPath = $_.FullName.Replace($PWD.Path, "$PWD.Path\output") New-Item -ItemType Directory -Path (Split-Path $outPath -Parent) -Force | Out-Null & tiffcp -r 20 $_.FullName $outPath }
方案2:PowerShell覆盖原文件
操作前请务必备份所有原TIFF文件,避免数据丢失
Get-ChildItem -Path . -Recurse -Include *.tif,*.tiff -File | ForEach-Object { $tmpPath = $_.FullName + ".tmp" & tiffcp -r 20 $_.FullName $tmpPath if ($LASTEXITCODE -eq 0) { Remove-Item $_.FullName -Force Move-Item $tmpPath $_.FullName } }
内容的提问来源于stack exchange,提问作者Marsh Randy
相关产品推荐
相关产品推荐

