批处理文件列出在Windows 7中的目录中的所有文件 [英] Batch file to list all files in a dir in windows 7

查看:476
本文介绍了批处理文件列出在Windows 7中的目录中的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图列出目录中的所有文件,然后编写使用批处理文件的文本文件。我想应该是这样的。

I'm trying to list all the files in a directory and then write that to a text file using a batch file. I think it should be something like

dir / (some flags here) >> files.txt

这将包含类似

a.exe
b.exe
c.exe

等。等等

推荐答案

您必须使用 / B 开关(只写文件列表,无需标题和其它信息)。

You have to use the /b switch (to write file list only, without header and other informations).

dir /b >> list.txt

然后,如果你需要列出在所有 .exe文件文件C:\\ WINDOWS 完整的命令是:

Then if you need to list all .exe files in c:\windows the full command is:

dir c:\windows\*.exe /b >> list.txt

请注意,>> 追加的列表中的文件。不要忘记您可以使用多个搜索模式,例如:

Please note that >> will append the list to the file. Do not forget you can use multiple search patterns, for example:

dir *.jpg;*.png /b > list.txt

这会写所有的 .JPG 巴纽文件(只名称,没有路径或其他任何信息)以文件 LIST.TXT (覆盖文件,如果它没有存在过)。

It'll write all the .jpg and .png files (only names, without path or any other informations) to the file list.txt (overwriting the file if it did exist before).

如果您需要排除你可以依靠 / A 开关上的目录(包括/根据属性排除项目)。你的情况要排除目录,那么你必须使用 -d

If you need to exclude directories you can rely on /a switch (to include/exclude items according to an attribute). In your case you want to exclude directories then you have to use -d:

dir /b /a-d >> list.txt

最后别忘了 DIR 可以用 / S 递归使用开关(列出匹配搜索模式的文件在给定的目录和所有子目录)和 / O 选项排序。使用 DIR /?有关的更多细节。

Finally do not forget dir can be used recursively with /s switch (to list files that match search pattern in the given directory and in all sub-directories) and sorted with /o option. Use dir /? for more details about that.

这篇关于批处理文件列出在Windows 7中的目录中的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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