将文本附加到保存文本文件功能大家好,
我将此函数用作 FOR 循环的一部分。
If( File Exists(location)
csvlist[N Items(FilesIndex)]= Open(location),
//else below
continue() & // I am not sure this & function works.
Save Text File( path || "\" || "error.txt", "
\!"File doesnt exist\!";
" ||char(location)) ;
);
基本上我想做的是,如果文件存在,我想打开该位置,如果不存在,我想创建一个文本文件并迭代循环。 另外,我想继续附加相同的错误。 txt 文件而不是每次都替换它。
有人知道怎么做吗? 我真的很感谢你的帮助。
谢谢。
回复:将文本附加到保存文本文件功能您的代码的逻辑就在那里。您似乎只是没有在脚本索引中查找语法或定义。
If( File Exists(location)
您缺少逗号和/或完成
If( File Exists(location),
或者
If( File Exists(location) == 1,
我不明白下一行的逻辑
csvlist[N Items(FilesIndex)]= Open(location),
按照它的编写方式,指向每个数据表的指针将被写在彼此之上,除非代码中的某个位置将 FilesIndex 添加到打开的数据表之间。我建议一个更简单、更安全的方法
dt = Open(location);
insert into(csvlist,dt),
不需要“继续”,代码会自动继续
如果您希望每次执行都覆盖该行的上一个执行,那么您的“保存文本文件”函数在语法上是正确的。如果您想添加到文件而不是在文件之上写入,请查看脚本索引,了解如何避免这样做。
我还建议,如果您希望将错误行添加到代码中,请在每一行中添加“\!n”,以强制每个列表到一个新行。
回复:将文本附加到“保存文本文件”功能continue() 有点像break。 它立即迭代并跳过它之后的所有内容。 例如
for(i=1, i<=50, i++,
errortxt = ""
If( File Exists( location ),
csvlist[N Items( FilesIndex )] = Open( location )
, //else
//could just concat one text file and save after the for loop
errortxt ||= "File doesnt exist" || Char( location ) ) || "\!n" //just a newline to make it more readable
//or if you just want to append to the file
Save Text File( path || "\" || "error.txt",
"File doesnt exist" || Char( location ) ) || "\!n",
mode("append")
);
Continue();
);
print("Doing other stuff")
);<BR />//if using the errortxt method<BR />Save Text File( path || "\" || "error.txt", errortxt);<BR />
在此脚本中,如果找不到该文件,它将附加到该文件或(实际上它两者都做)将错误连接到 errortxt 字符串。 一旦点击Continue(),它将立即开始for循环。 跳过打印(“做其他事情”)。 查看帮助>>脚本索引下的脚本索引,它有关于函数及其工作原理的非常好的文档和示例。
希望这有帮助。
回复:将文本附加到“保存文本文件”功能脚本索引是查找 JSL 函数的好地方。
Scripting Index showing mode("append")Scripting Index showing mode("append")脚本索引显示模式(“追加”)
您可能不想这样使用 continue() 。 Continue() 和 Break() 是 JSL 中的语句,它们跳转到包含循环的末尾,并继续循环或跳出循环。 可能你想要
for(i=1,i<10,i+=1,
if( condition,
doSomethingIfTrue();
doMoreThingsIfTrue();
, // else
doSomethingIfFalse();
continue();
); // end of if statement
codeThatIsSkippedByContinue();
); // end of for loop