Merge all .txt files in all subdirectories in one txt file
Asked Answered
W

2

6

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.

Wilmott answered 31/1, 2014 at 11:32 Comment(0)
B
13

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

for /r "c:\folder" %%a in (*.txt) do type "%%a" >>"bigfile.txt"
Brume answered 31/1, 2014 at 13:14 Comment(1)
for /r "c:\Users\Acer\Desktop\UJC\files\" %a in (*.txt) do type "%a" >>"c:\Users\Acer\Desktop\UJC\files\bigfile.txt"Flagwaving
W
0

Try:

@echo off
set "folder=folder"
for /F %%a in ('dir /b /s %folder%') do (
 if "%%~xa" == ".txt" (
  (echo/------------------------------
  type %%~a
  echo/)>>"%~dp0list.txt"
)
)
Whencesoever answered 31/1, 2014 at 11:56 Comment(1)
Did you change folder to your main folder?Whencesoever

© 2022 - 2024 — McMap. All rights reserved.