1

I have 10 files like below:

  • file1.txt (file content = "i contain text for file1")
  • file2.txt (file content = "i contain text for file2")
  • file3.txt (file content = "i contain text for file3")

and so


I am trying to do a TYPE command like:

type file*.txt > OUTPUT.txt

this works to output the file contents only. i need output to also have filename for each file.

my output.txt file should look like this:

file1.txt = "i contain text for file1"
file2.txt = "i contain text for file2"
file3.txt = "i contain text for file3"
  • findstr "^" "file*.txt" – JosefZ Oct 15 '15 at 6:44
  • Thank you @JosefZ. this was so simple and works exactly the way i want. – superuser10105050 Oct 15 '15 at 13:00
1

Create a batch file called proc.bat which contains:

echo %1=>>output.txt
type %1>>output.txt

Then use this command:

for %v in (file*.txt) do proc %v
1

Use next command from cmd window:

>output.txt (for /F "tokens=1* delims=:" %G in ('findstr "^" "file*.txt"') do @echo %G = "%H")

If used in a batch script, double percent signs in for loop inner variables (i.e. %%G, %%H instead of %G, %H respectively):

@echo off
>output.txt (for /F "tokens=1* delims=:" %%G in ('findstr "^" "file*.txt"') do echo %%G = "%%H")

Resources (required reading):

0

You can try:

for /l %f in (1,1,3) do echo|set /p="File %f = " >> output.txt & type file%f.txt >> output.txt

This will yield a file that looks like:

File 1 = Text in file1
File 2 = Text in file2
File 3 = Text in file3

The for /l command counts from 1 to 3 in increments. In general (start,increment,end).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy