將文本附加到保存文本文件功能大家好,
我將此函數用作 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