1、一次逐行读出txt文本

import console;
for lineTxt in io.lines("C:\Users\Administrator\Desktop\aaa.txt"){
console.log(lineTxt)
}
console.pause(true);

2、把文本每行以空隔为界,逐行读到listview里

import win.ui;
//import string;
/*DSG{{*/
var winform = win.form(text="aardio Form";right=459;bottom=372;parent=...)
winform.add(
listview={cls="listview";left=6;top=33;right=452;bottom=253;bgcolor=16777215;edge=1;z=1}
)
/*}}*/

winform.listview.insertColumn("序号",40)
winform.listview.insertColumn("测试",200)
winform.listview.insertColumn("测试",200)

winform.listview.clear();
var x = 1;
for line in io.lines("C:\Users\Administrator\Desktop\aaa.txt") { //采取分行迭代方法读取 test.txt文本的内容;
var a,b = table.unpack(string.split(line,"< >")); //string.split以“ ”为分割符分割读取的文本行 然后把分开的值分别赋值给a,b,模式匹配详细请参考帮助文档和论坛;
winform.listview.addItem({tostring(x);a;b;});//显示到listview控件;
x++;
}

winform.show()
win.loopMessage();

3、查找txt内文本的最大行数

io.open();//打开控制台   
var lines = 0;
for line in io.lines("C:\Users\Administrator\Desktop\aaa.txt") {
lines++;
}
io.print("您输入的是" ,lines );
execute("pause") //按任意键继续

4、这个代码就有意思了,上面读数据,最后写总行数;

import console;
var lines=0
for line in io.lines("C:\Users\Administrator\Desktop\aaa.txt"){
console.log(line)//这是逐行读的总的数据
lines++
}
console.log(lines)//这是总的行数
console.pause(true);

5、(1)文本分割

import console;
var a,b = table.unpack(string.split("apple banana"," "))
console.log(a)
console.log(b)
execute("pause") //按任意键继续
(2)字符拼接
io.open(); //打开控制台窗口
str = "12345678";
t = string.split(str); //按单个字符开始拆分
io.print(tostring(t[1])++tostring(t[2])++tostring(t[3]) +"*");
execute("pause") //按任意键继续
io.close();//关闭控制台

6、查找某个数据在等几行

import console;
var num = {}
for line in io.lines("C:\Users\Administrator\Desktop\123.txt") {
table.push(num,line)
if( string.find(line,"李四") ){
console.log("发现李四在第",#num,"行")
}
}
execute("pause") //按任意键继续

7、找某个关键字,并找出空格前、后的数据

import console;
for line in io.lines("C:\Users\Administrator\Desktop\123.txt") {
var a,b = table.unpack(string.split(line,"< >"));
if( string.find(line,"001") ){
console.log("找到同行空格后的数据为",b)
console.log("找到同行空格前的数据为",a)
}
}
execute("pause") //按任意键继续

8、目录基本操作

import fsys
import win
//创建当前目录下的新目录,清空目录重建,返回目录路径
$path = fsys.createDir(fsys.getCurDirO+"\新目录\",true)
if fsys.isDir($path){
win.msgbox("是目录")
//语句块内对文件或目录都有效[*
//移动
fsys.move($path,"e:\")
//复制
fsys.copy("e:\新目录",$path)
//改名
fsys.rename("e:\新目录","e:\目录")
//删除目录,支持空目录,可以使用数组册删除多人目录
fsys.delete(("e:\目录";$path)

//搜索路径,返回目录下文件,目录数组
$list,$path = fsys.list("E:\ aardio")
win.msgbox($list)
win.msgbox($path)

9、遍历目录

import win.ui;
/*DSG{{*/
var winform = win.form(text="aardio form";right=360;bottom=422)
winform.add(
button={cls="button";text="Button";left=227;top=15;right=332;bottom=63;z=2};
edit={cls="edit";left=11;top=11;right=212;bottom=408;edge=1;multiline=1;z=1}
)
/*}}*/

import fsys;
winform.button.oncommand = function(id,event){
winform.edit.text = "";
var filenames = {};
fsys.enum( fsys.getTempDir(), "*.tmp",
function(dir,filename,fullpath,findData){
if(filename){
table.push(filenames, filename);
//winform.edit.printf('%s\n', filename)
}
},
false
);
for(i=1; #filenames;1){
winform.edit.printf('%s\n', filenames[i])
}

}

winform.show();
win.loopMessage();
return winform;