I need a batch file that will add the text \"Write In\" in a new line at the beginning of the content of hundreds of .txt files without removing any existing text. I found somet
I found a way that is not very clean and will take a while for bigger files, but it works out for me:
@echo off
for /r "%~dp0" %%f in (*.txt) do (
echo Processing file %%f
>"%%~f.2" (
echo "Text to append here"
type "%%~f"
)
del "%%~f"
ren "%%~f.2" "%%~nxf"
)
pause
Loops recursively through all .txt
-files in the batch-files directory.
Creates a new file with the name oldName.txt.2
and files it with the text to add and the rest of the oldfiles content.
Deletes the old file and renames the new file to the name of the old one.
The addition of .2
to the file ending is needed to make sure it does not get processed again by the loop.
Of course you can add multiple lines by multiplying the echo lines.
You can as well add text to the end of the file like this with adding the echo lines after the type
line.