使用一个for循环遍历目录中的所有文件 [英] Iterate all files in a directory using a for-loop

查看:1100
本文介绍了使用一个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)

(thanks @agnul)

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

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