This can be easily done with a batch-file, using the >>
redirection operator, given that every file ends with a line-break:
for %%F in ("%TargetFolder%\*.js") do (
>> "%%~F" echo/This is the new line of text.
)
Or if you want to recurse into sub-directories also:
for /R "%TargetFolder%" %%F in ("*.js") do (
>> "%%~F" echo/This is the new line of text.
)
You can of course first explicitly append a line-break:
for %%F in ("%TargetFolder%\*.js") do (
>> "%%~F" (
echo/
echo/This is the new line of text.
)
)
Or equivalently for the recursive approach, of course.
If you want to append a line-break only in case the file does not already end with such, you could do the following:
for %%F in ("%TargetFolder%\*.js") do (
rem /* Count the number of lines that contain zero or more characters at the end;
rem this is true for every line except for the last when it is not terminated
rem by a line-break, because the `$` is anchored to such: */
for /F %%D in ('findstr ".*$" "%%~F" ^| find /C /V ""') do (
rem // Count the total number of lines in the file:
for /F %%C in ('^< "%%~F" find /C /V ""') do (
>> "%%~F" (
rem // Compare the line counts and conditionally append a line-break:
if %%D lss %%C echo/
echo/This is the new line of text.
)
)
)
)
And again equivalently for the recursive approach.