Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file 成批连接文本_Batch File - Fatal编程技术网

Batch file 成批连接文本

Batch file 成批连接文本,batch-file,Batch File,我的文件夹结构中有sql文件,如下所示: C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer1\test.sql C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer2\test.sql C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer3\test.sql C:\Users\Peter\Desktop\SQL_F

我的文件夹结构中有sql文件,如下所示:

C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer1\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer2\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer3\test.sql
C:\Users\Peter\Desktop\SQL_FILES\data_structure\customer4\test.sql
........
我想制作一个脚本来读取路径(C:\Users\Peter\Desktop\SQL\U文件), 文件名(test.sql)和文本 然后将文本连接到每个test.sql文件的末尾

你能帮我吗

提前谢谢

:: Hide Command and Set Scope
@echo off
setlocal EnableExtensions
mode 140,50


set /p AbsolutePath="Enter the path of root folder :"

echo.
set /p FileName="Enter the filename with it's extension (ie. test.sql):"

echo.
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 Sending message. . . & goto done_typing
echo      %new_line% >> temp.txt
goto still_typing

:done_typing
echo done

:End
endlocal
pause >nul
在执行批处理假设后,我在文本中添加一个空行和两个插入:

INSERT INTO TEST(COL1,COL2,COL3) VALUES(3,4,5);

INSERT INTO TEST(COL1,COL2,COL3) VALUES (1,2,3);

INSERT INTO TEST(COL1,COL2,COL3) VALUES (2,3,4);

下面的批处理文件使用不同的方法来执行相同的操作,但方法更简单。此代码可以在您希望的任何位置进行修改;例如,如果不希望,文件名必须包含通配符

@echo off
setlocal

set /p "AbsolutePath=Enter the path of root folder: "
echo/
set /p "FileName=Enter the filename with a wild-card (ie. test*.sql): "
echo/

echo Enter your inserts
echo Press Ctrl-Z and Enter when finished
copy CON temp.txt > NUL
echo/
echo Typing done
echo/

for /R "%AbsolutePath%" %%a in (%FileName%) do type temp.txt >> "%%a"

请提供一个开始数据的示例,以及一个您希望结果是什么的示例。更好的动词是
append
不是
concatenate
,而是除了在
temp.txt
中追加行之外(不初始化文件)没有循环来迭代文件夹/文件并通过copy或
type test.txt>>test进行追加。sql
我修改了初始问题。谢谢1。除了设置
绝对路径
文件名
的值外,我看不到任何引用。2.这在cmd批处理以外的语言中可能更容易实现;我建议使用PowerShell,但VBScript或JScript也是合理的选择。非常感谢您的回答,但如果我有类似testFile.txt的文件,请将文本添加到此文件。我怎样才能避免这种情况?我试过test.sql*,它很管用。。
@echo off
setlocal

set /p "AbsolutePath=Enter the path of root folder: "
echo/
set /p "FileName=Enter the filename with a wild-card (ie. test*.sql): "
echo/

echo Enter your inserts
echo Press Ctrl-Z and Enter when finished
copy CON temp.txt > NUL
echo/
echo Typing done
echo/

for /R "%AbsolutePath%" %%a in (%FileName%) do type temp.txt >> "%%a"