循环打开文件、更改列名称并以原始格式保存大家好,
我尝试编写一个脚本来打开一系列文件 (.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() 包装器,或者让它在捕获错误时执行某些操作。