Merge all .txt files in all subdirectories in one txt file

老子叫甜甜 提交于 2019-12-20 14:41:10

问题


I want to merge content of all .txt files in my directory (containing subdirectories) to one txt file. I need to do this:

xcopy text1.txt + text2.txt text3.txt

but in a for loop which takes all text files in current directory. i assume something like this:

for \r ___ in ___ do copy list.txt

Thanks in advance.


回答1:


Use one % instead of two %% to run it from the command line.

for /r "c:\folder" %%a in (*.txt) do type "%%a" >>"bigfile.txt"



回答2:


Try:

@echo off
set "folder=folder"
for /F %%a in ('dir /b /s %folder%') do (
 if "%%~xa" == ".txt" (
  (echo/------------------------------
  type %%~a
  echo/)>>"%~dp0list.txt"
)
)


来源:https://stackoverflow.com/questions/21479062/merge-all-txt-files-in-all-subdirectories-in-one-txt-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!