我想制作一个新的 .txt 文件,我从 .script 文件加载参数。它在根中工作正常。.script 文件位于根目录中。结果是:
- 192.121.2.2登录Lucey密码红色
- 192.321.2.1登录史蒂夫密码苹果
.
if FindFirst('*.*', faAnyFile, Search) = 0 then
begin
while FindNext(Search) = 0 do
begin
if FileExists(Search.Name) then
begin
if pos('.txt', Search.Name) <> 0 then
begin
Assignfile(txtfile, Search.Name);
Erase(txtfile);
end;
end;
end;
end;
findclose(Search);
if FindFirst('*.*', faAnyFile, Search) = 0 then
begin
while FindNext(Search) = 0 do
begin
if FileExists(Search) then
begin
if pos('.script', Search.Name) <> 0 then
begin
data_file := TStringList.Create;
data_file.LoadFromFile(Search.Name);
txtdata := data_file.Strings[1].+ 'login' + data_file.Strings[2] +
'password' + data_file.Strings[3];
txtfile := TStringList.Create;
if FileExists('.txt') then
begin
txtfile.LoadFromFile('.txt');
end;
txtfile.Add(txtdata);
txtfile.SaveToFile('.txt');
end;
end;
end;
end;
findclose(Search);
但是如果我想添加 C:\Script\Files 我使用的代码是错误的,有什么问题?请帮忙!
if FindFirst('c:\Script\Files\*.*', faAnyFile, Search) = 0 then
begin
while FindNext(Search) = 0 do
begin
if FileExists(Search.Name) then
begin
if pos('c:\Script\Files\.txt', Search.Name) <> 0 then
begin
Assignfile(txtfile, Search.Name);
Erase(txtfile);
end;
end;
end;
end;
findclose(Search);
if FindFirst('*.*', faAnyFile, Search) = 0 then
begin
while FindNext(Search) = 0 do
begin
if FileExists(Search) then
begin
if pos('.script', Search.Name) <> 0 then
begin
data_file := TStringList.Create;
data_file.LoadFromFile(Search.Name);
txtdata := data_file.Strings[1] + 'login' + data_file.Strings[2] +
'password' + data_file.Strings[3];
txtfile := TStringList.Create;
if FileExists('c:\Script\Files\.txt') then
begin
txtfile.LoadFromFile('c:\Script\Files\.txt');
end;
txtfile.Add(txtdata);
txtfile.SaveToFile('c:\Script\Files\.txt');
end;
end;
end;
end;
findclose(Search);
结果是:
- 192.121.2.2登录Lucey密码红色
- 192.121.2.2登录Lucey密码红色
- 192.321.2.1登录史蒂夫密码苹果
第一项显示两次,依此类推。