使用“for"循环迭代目录中的所有文件 [英] Iterate all files in a directory using a 'for' loop

查看:16
本文介绍了使用“for"循环迭代目录中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 for 循环遍历目录中的每个文件?

How can I iterate over each file in a directory using a for loop?

我怎么知道某个条目是一个目录还是一个文件?

And how could I tell if a certain entry is a directory or if it's just a file?

推荐答案

这会列出当前目录中的所有文件(并且仅列出文件):

This lists all the files (and only the files) in the current directory:

for /r %i in (*) do echo %i

此外,如果您在批处理文件中运行该命令,则需要将 % 符号加倍.

Also if you run that command in a batch file you need to double the % signs.

for /r %%i in (*) do echo %%i

(感谢@agnul)

这篇关于使用“for"循环迭代目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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