从子目录中的多个 CSV 追加 txt 文件
我正在尝试编写一个批处理文件,它将直接子目录中的所有 *.csv 文件附加到当前目录中的单个文本文件中。
从各种来源,我设法拼凑出这段代码,该代码适用于当前目录中的文件,但不适用于子目录
for %%a in (*.csv) do (type %%a >> csvreport.txt)
如果有人可以帮助我,我将非常感激,因为我尝试了各种使用通配符的方法,但没有成功。
I am trying to write a batch file which will append all *.csv files in the immediate subdirectories to a single text file in the current directory.
From various sources I have managed to piece together this code which works fine for files in the current dir but not sub-dirs
for %%a in (*.csv) do (type %%a >> csvreport.txt)
If anybody could help me with this I would be extremely grateful as I have tried various approaches with wildcards but without success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
还有另一种选择...
编辑:再阅读一下您的详细信息...您只需要直接目录,您可以这样做:
Yet another option...
EDIT: Reading your details a bit more ... you want just the immediate directories, you can do this:
/R表示递归,后面的参数是启动的文件夹(.\是当前目录)。
如果运行
for /?
,您可以找到更多信息The /R indicates recursive and the parameter afterward is the folder in which to start (.\ is the current directory).
You can find up more if you run
for /?
使用 /R 标志将遍历所有子目录树。您可以嵌套“for”语句,使其仅适用于直接子目录,但不适用于其子目录。
Using the /R flag will traverse all subdirectory trees. You can nest the 'for' statements to only work with the immediate subdirectories but not their subdirectories.