Windows 如何使用.bat脚本使用这些sqlite指令创建文件?

Windows 如何使用.bat脚本使用这些sqlite指令创建文件?,windows,sqlite,batch-file,cmd,Windows,Sqlite,Batch File,Cmd,我想使用.bat脚本创建下一个sqlite指令,并将它们保存在temp.txt文件中。问题是指令的某些部分是可变的,并且依赖于当前目录中的文件列表 例如: 在我当前的目录中,我有下一个文件:file1.txt、file2.txt、file3.txt和其他一些我不在乎的文件 所以我需要创建下一个sqlite语句: insert into table1(fileName) values('THE VARIABLE FILE NAME'); insert into table2(something1)

我想使用.bat脚本创建下一个sqlite指令,并将它们保存在temp.txt文件中。问题是指令的某些部分是可变的,并且依赖于当前目录中的文件列表

例如:

在我当前的目录中,我有下一个文件:file1.txt、file2.txt、file3.txt和其他一些我不在乎的文件

所以我需要创建下一个sqlite语句:

insert into table1(fileName) values('THE VARIABLE FILE NAME');
insert into table2(something1) select (idTable1) from table1 where fileName = 'THE VARIABLE FILE NAME';
.import THE VARIABLE FILE NAME table3
所以句子必须是这样的:

insert into table1(fileName) values('file1.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file1.txt';
.import file1.txt table3
insert into table1(fileName) values('file2.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file2.txt';
.import file2.txt table3
insert into table1(fileName) values('file3.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file3.txt';
.import file3.txt table3
sqlite3 < temp.txt
echo. 2> temp.txt
echo TheseAreMyInstructions >> temp.txt
保存这些说明的文件名为temp.txt

因此,在myScript.bat的末尾,我想执行如下操作:

insert into table1(fileName) values('file1.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file1.txt';
.import file1.txt table3
insert into table1(fileName) values('file2.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file2.txt';
.import file2.txt table3
insert into table1(fileName) values('file3.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file3.txt';
.import file3.txt table3
sqlite3 < temp.txt
echo. 2> temp.txt
echo TheseAreMyInstructions >> temp.txt
我还知道我可以创建一个空文件,如下所示:

insert into table1(fileName) values('file1.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file1.txt';
.import file1.txt table3
insert into table1(fileName) values('file2.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file2.txt';
.import file2.txt table3
insert into table1(fileName) values('file3.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file3.txt';
.import file3.txt table3
sqlite3 < temp.txt
echo. 2> temp.txt
echo TheseAreMyInstructions >> temp.txt
我可以将我想要的文本写入temp.txt文件,如下所示:

insert into table1(fileName) values('file1.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file1.txt';
.import file1.txt table3
insert into table1(fileName) values('file2.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file2.txt';
.import file2.txt table3
insert into table1(fileName) values('file3.txt');
insert into table2(something1) select (idTable1) from table1 where fileName = 'file3.txt';
.import file3.txt table3
sqlite3 < temp.txt
echo. 2> temp.txt
echo TheseAreMyInstructions >> temp.txt
所以myScript应该这样开始

@echo off // Wont show more info...
echo. 2> temp.txt // Will create the empty file
FOR %%a IN (dir f*.txt /b) DO echo insert into table1(fileName) values('%%a') >> temp.txt
我试过这样的方法

@echo off // Wont show more info...
echo. 2> temp.txt // Will create the empty file
FOR %%a IN (dir f*.txt /b) DO echo insert into table1(fileName) values('%%a') >> temp.txt
我不知道如何将其他说明放在

结果不是我期望的

我的temp.txt文件中的结果如下:

insert into table1(fileName) values('dir') // This should not be here!
insert into table1(fileName) values('file1.txt') 
insert into table1(fileName) values('file2.txt') 
insert into table1(fileName) values('file3.txt') 
insert into table1(fileName) values('/b') // This should not be here!
请帮帮我,我真的必须这么做


谢谢你的帮助!;)

要对一组文件执行命令,只需指定文件模式:

用于(f*.txt)中的%%a(
echo…%%a>>sql.txt
echo%%a..>>sql.txt
)

为什么要将文件名
dir
/b
放入文件列表?我的temp.txt文件中不需要这些信息。。。我只是不知道如何让这些东西消失。正如我所说,结果并不是我所期望的。它起了作用,但我不得不在所有括号前加上“^”。我不知道。。。而且我使用了错误的for循环。。。谢谢我的朋友们。这就是我所做的:
@echo关闭echo。2> (f*.txt)do中%%a的temp.txt(echo insert into table1^(fileName^)value^('%a'^)>>temp.txt echo insert into table2^(something1^)从表1中选择^(idTable1^),其中fileName='%a'>>temp.txt echo.import%%a table3>>temp.txt)