循環開啟檔案、更改列名稱並以原始格式儲存大家好,
我嘗試編寫一個腳本來打開一系列文件 (.dx) 並更改每個文件的其中一列中的文字。 我設法使其單獨適用於一個或兩個文件,但如果我嘗試一組四個文件,則會開始無限循環。 有人可以幫忙嗎? 有可能問題出在文件上,但我想先檢查一下腳本,因為我是 jsl 的新手。 理想情況下,我希望將檔案儲存為 dx,而不是 jmp。
Files = Pick File( "Select File(s)", "G:\Retention Compliant\Research\Analytical\Projects\IR database", {"All Files|*"}, 1, 0, "", "multiple" );
For( i = 1, i <= N Items( Files ), i++,
Try( dt = Open( Files[i], "text" ) );
wait( 0 );
For( n = 1, n <= N Items (Files), n++,
colList = dt << get column names( character, string );
For( i = 1, i <= N Items( colList ), i++,
selRows = dt << get rows where(
Column( dt, colList[i] )[Row()] == "##YUNITS= % Transmittance" | Column( dt, colList[i] )[Row()] == "##YUNITS= % T"
);
If( N Rows( selRows ) > 0,
Column( dt, colList[i] )[selRows] = "##YUNITS= % T";
);
);
) );自動化和腳本編寫回覆:循環開啟檔案、更改列名稱並以原始格式儲存我已經用我發現的問題註釋了下面的腳本。我很驚訝你可以讀 .dx 檔案。JMP當然不支援寫入.dx檔案(據我所知)。
Files = Pick File(
"Select File(s)",
"G:\Retention Compliant\Research\Analytical\Projects\IR database",
{"All Files|*"},
1,
0,
"",
"multiple"
);
For( i = 1, i <= N Items( Files ), i++,
// Open one file
Try( dt = Open( Files[i], "text" ) );
Wait( 0 );
// Loop from 1 to the number of files (even though only 1 file has been opened)
For( n = 1, n <= N Items( Files ), n++,
// Here you will be reading the column names in for the first file over and over
colList = dt << get column names( character, string );
// Loop using "i" as the index across all of the columns....in the first file
// since that is all we have read in.....but since you are using "i", you will
// be creating an infinate loop, since you are using "i" for the first loop
// and you will be interferring with the assumed stepping for the outter loop
For( i = 1, i <= N Items( colList ), i++,
selRows = dt << get rows where(
// You are not in a formula, so the Row() function will not provide a predictable result
Column( dt, colList[i] )[Row()] == "##YUNITS= % Transmittance" | Column( dt, colList[i] )[Row()] ==
"##YUNITS= % T"
);
If( N Rows( selRows ) > 0,
Column( dt, colList[i] )[selRows] = "##YUNITS= % T"
);
);
);
);回覆:循環開啟檔案、更改列名稱並以原始格式儲存不確定 dx 是什麼,但您可以使用 .csv 副檔名儲存,並且可能很接近。
回覆:循環開啟檔案、更改列名稱並以原始格式儲存謝謝克雷格,它現在可以處理所有文件並且沒有錯誤! 有什麼想法如何以原始格式(.dx)保存並最好保留檔案名稱嗎?
回覆:循環開啟檔案、更改列名稱並以原始格式儲存1) 使用編輯器右鍵彈出視窗重新格式化 JSL。 您將能夠更好地看到嵌套。
2)您在內循環中重複使用 i 變數。 這就是導致循環的原因。
3) 刪除 try() 包裝器,或讓它在擷取錯誤時執行某些操作。