Windows 批处理文件循环通过目录来处理文件? [英] Windows Batch File Looping Through Directories to Process Files?

查看:40
本文介绍了Windows 批处理文件循环通过目录来处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要编写/使用一个批处理文件来为我处理一些图像.

I need to write/use a batch file that processes some imagery for me.

我有一个充满嵌套文件夹的文件夹,在这些嵌套文件夹中的每一个文件夹中还有一个文件夹,其中包含许多 TIF 图像,每个文件夹中的图像数量各不相同.我还有一个批处理文件,我们将它称为 ProcessImages.bat for Windows,您可以删除"它.这些 TIF 文件(或在调用 bat 时显然在命令行列表中指定它们);它基于我拥有的 EXE 创建一个包含我所有图像处理的新文件夹.

I have one folder full of nested folders, inside each of these nested folders is one more folder that contains a number of TIF images, the number of images vary in each folder. I also have a batch file, lets call it ProcessImages.bat for Windows that you can "drop" these TIF files on (or obviously specify them in a command line list when invoking the bat); upon which it creates a new folder with all my images process based on an EXE that I have.

好消息是,因为 bat 文件使用了您删除"的文件夹中的路径.到它上面,我可以选择一个文件夹的所有 TIF 并将其放下来进行处理......但是当我继续手动为 300 个左右的 TIF 文件夹执行此操作时,我发现它使我的系统陷入了令人难以置信的困境,并且如果我一次只能处理这些(无需手动处理),那就太好了.

The good thing is that because the bat file uses the path from the folders you "drop" onto it, I can select all the TIFs of one folder and drop it to do the processing... but as I continue to manually do this for the 300 or so folders of TIFs I have I find it bogs my system down so unbelievably and if I could only process these one at a time (without manually doing it) it would be wonderful.

所有这一切...有人能指出我正确的方向(对于 Windows bat 文件 AMATEUR),我可以编写一个 Windows bat 脚本,我可以从目录内部调用该脚本并让它遍历所有包含在该目录中的目录...并一次对每组图像运行我的处理批处理文件?

All that said... could someone point me in the right direction (for a Windows bat file AMATEUR) in a way I can write a Windows bat script that I can call from inside a directory and have it traverse through ALL the directories contained inside that directory... and run my processing batch file on each set of images one at a time?

推荐答案

您可以在 Batch 中编写递归算法,让您精确控制在每个嵌套子目录中的操作:

You may write a recursive algorithm in Batch that gives you exact control of what you do in every nested subdirectory:

@echo off
call :treeProcess
goto :eof

:treeProcess
rem Do whatever you want here over the files of this subdir, for example:
for %%f in (*.tif) do echo %%f
for /D %%d in (*) do (
    cd %%d
    call :treeProcess
    cd ..
)
exit /b

这篇关于Windows 批处理文件循环通过目录来处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆