1

I want to add file name to the beginning of every file and line break

(-------------------------------------------------------) --> like this

                                           --> empty line after line break

to every file with to extension of .cpp

This command will add file name to every line of file and combine those files into one output file.

findstr "^" *.cpp >C:\users\user\desktop\output.txt

Could you help me modify this command?

1 Answer 1

1

Try a for loop file by file (*.cpp) and print each Name and eXtension (%%~nxi) redirecting to your output.txt file, then add the line at the end of each looped file with type “current file in loop + echo;

@echo off

cd/d "D:\Full\Path\To\cpp\Files\Folder"

for %%i in (*.cpp)do >>"Output.txt" (
     set /p "'=%%~nxi" <nul & echo;
     type "%%~fi" & echo;
    )

Additional resources:

2
  • thanks, this works
    – devec
    Commented Apr 10, 2022 at 15:19
  • Good to know! Thanks
    – Io-oI
    Commented Apr 10, 2022 at 15:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .