|
function readys() {
var fs = api.require('fs');
fs.readDir({
path: 'fs://userinfo/pull/record'
}, function (ret, err) {
if (ret.status) {
var record = ret.data;
console.log(record);
var newr
for (var i = 1; i < record.length; i++) {
var r = record.substring(6, 8)
console.log(r);
//这里执行两次第一次是01第二次是02
fs.readByLength({
path: 'fs://userinfo/pull/record/record' + r + '.txt',
substring: {
start: 0
}
}, function (ret, err) {
if (ret.status) {
var lens = ret.content.length;
var newid = r + ret.content.substring(2, lens)
console.log(r);
//然后到修改文件内容的时候执行的两次都是02
fs.writeByLength({
path: 'fs://userinfo/pull/record/record' + r + '.txt',
content: newid,
place: {
start: 0
}
}, function (ret, err) {
if (ret.status) {
console.log(JSON.stringify(ret));
} else {
console.log(JSON.stringify(err));
}
});
} else {
console.log(JSON.stringify(err));
}
});
}
} else {
console.log(JSON.stringify(err));
}
});
}
[2022-6-10 16:27:41][INFO] 01 at pullGrades.html:51
[2022-6-10 16:27:41][INFO] 02 at pullGrades.html:51
[2022-6-10 16:27:41][INFO] 02 at pullGrades.html:61
[2022-6-10 16:27:41][INFO] 02 at pullGrades.html:61
这是控制台输出记录
为什么后面两次都是02呢
|
|