-1

From the Windows command prompt it's possible to collect all text files into one file using

copy *.txt all_text_files.txt

Is it possible to add the name of each file added in front of the file in question? In my example I have two text files a & b.

a.txt consists of one line:

Cheese

b.txt also consists of one line:

Monkeys

The new file would be:

a.txt
Cheese
b.txt
Monkeys
Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Mr Mystery Guest
  • 1,464
  • 1
  • 18
  • 47

2 Answers2

2

If you write it directly in the command line, this should work. If you want to make a script I believe you need to put double %

for %f in (*.txt) do (
    echo "%f"
    type "%f"
) > all_text_files.txt
Nico
  • 574
  • 1
  • 4
  • 19
1
type *.txt >allfiles.out 2>&1
ren allfiles.out allfiles.txt

type types all matching files. The file contents goes to STDOUT, the filenames are printed to STDERR. So just redirect both to the new file. Choose a different extension to avoid recursive handling.

Stephan
  • 53,940
  • 10
  • 58
  • 91