I am sorry I am newbie in batch scripting, but I need a script to append text to files.
I have sql files in a folder structure like the following :
C:\Users\George\Desktop\SQL_FILES\data\Folder1\test.sql
C:\Users\George\Desktop\SQL_FILES\data\Folder2\test.sql
C:\Users\George\Desktop\SQL_FILES\data\Folder3\test.sql
C:\Users\George\Desktop\SQL_FILES\data\Folder4\test.sql
........
I want to make a script which reads the path (C:\Users\George\Desktop\SQL_FILES), the name of the file(test.sql) and a text and then append the text in the end of each test.sql file.
Could you help me please ?
Thanks in advance
Code: Select all
:: Hide Command and Set Scope
@echo off
setlocal EnableExtensions
set /p AbsolutePath="Enter the path of root folder :"
set /p FileName="Enter the filename with it's extension (ie. test.sql):"
echo Enter your inserts
echo Press Enter twice when finished
echo (text may not contain ^<, ^>, ^|, ^&, or un-closed quotes)
ver > NUL
set new_line=""
:still_typing
set /p new_line=">"
if errorlevel 1 echo. >> temp.txt & set /p new_line=">"
if errorlevel 1 echo Text initiated. . . & goto append_text
echo %new_line% >> temp.txt
goto still_typing
:append_text
for .......
:End
endlocal
pause >nul
=====================================
For example : The file test.sql for example contains initially :
INSERT INTO TABLE_TEST(COL1,COL2,COL3) VALUES('a','b','c');
And after the execution of batch supposing I add two empty lines and two inserts in the text :
INSERT INTO TEST(COL1,COL2,COL3) VALUES('a','b','c');
INSERT INTO TEST(COL1,COL2,COL3) VALUES('f','b','c');
INSERT INTO TEST(COL1,COL2,COL3) VALUES('b','g','c');