批处理文件:列出目录中的所有文件,打印为.txt,并将输出文件放在所有子目录中 [英] Batch Files: List all files in a directory, print as .txt and place output file in all sub directories

查看:583
本文介绍了批处理文件:列出目录中的所有文件,打印为.txt,并将输出文件放在所有子目录中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。


搜索到处,我找到教程使用dir命令打印目录和子目录中的文件列表,如下所示:

1.
Searched everywhere, I do find tutorials to print list of files in directory and sub directories using dir command as follows:

@echo off
dir /S > list.txt
pause

以上代码将返回list.txt中的所有文件。我们可以使用交换机来获取各种格式的列表。
我想要做的是:
当我运行批处理文件输出文件list.txt应放在所有子目录中,不仅在批处理文件的目录中执行。


2。


我试图将list.txt重命名为%当前目录名称%.txt并具有没有线索来实现。

Above code will return all files in list.txt. We can use switches to get lists in various formats. What I am trying to do is: When I run batch file output file list.txt should be placed in all Sub Directories and not only in the directory from batch file is being executed.
2.
I am trying to to rename list.txt as %current directory name%.txt and having no clues to achieve that.

推荐答案

这将使用for变量修饰符作为编写list.txt文件所需的目录。

This uses the for variable modifiers as the directory it needs to write the list.txt file.

del /s list.txt
for /F "delims=" %%G IN ('dir /b /s') DO @echo "%%G">>"%%~dpGlist.txt"

这篇关于批处理文件:列出目录中的所有文件,打印为.txt,并将输出文件放在所有子目录中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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