小程序
小游戏
企业微信
微信支付
扫描小程序码分享
假如我在第一次读取文件的时候将这些文件路径都存到一个csv下,第二次就从csv中读取这些文件路径,而不是通过
或者
来再次获取文件路径,效率会不会提高
1 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
function
cleanAllFiles(path, newAssets, finish) {
fs.readdir({
dirPath: path,
success:
(res) {
var
files = res.files;
(
next(idx) {
if
(idx < files.length) {
dirPath = path +
'/'
+ files[idx];
stat = fs.statSync(dirPath);
(stat.isDirectory()) {
cleanAllFiles(dirPath, newAssets,
() {
next(idx + 1);
});
}
else
{
// remove old assets
(newAssets && newAssets.indexOf(dirPath) !== -1) {
return
;
fs.unlink({
filePath: dirPath,
cc.log(
'unlink local file '
+ dirPath +
' successfully!'
);
},
fail:
cc.warn(
'failed to unlink file('
'): '
+ res ? res.errMsg :
'unknown error'
complete:
finish && finish();
})(0);
比如官方WX-Downloader.js里这个cleanAllFiles,假如我把这个readdir改成从预存的csv中读取,效率能提高吗
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
functioncleanAllFiles(path, newAssets, finish) {fs.readdir({dirPath: path,success:function(res) {varfiles = res.files;(functionnext(idx) {if(idx < files.length) {vardirPath = path +'/'+ files[idx];varstat = fs.statSync(dirPath);if(stat.isDirectory()) {cleanAllFiles(dirPath, newAssets,function() {next(idx + 1);});}else{// remove old assetsif(newAssets && newAssets.indexOf(dirPath) !== -1) {next(idx + 1);return;}fs.unlink({filePath: dirPath,success:function() {cc.log('unlink local file '+ dirPath +' successfully!');},fail:function(res) {cc.warn('failed to unlink file('+ dirPath +'): '+ res ? res.errMsg :'unknown error');},complete:function() {next(idx + 1);}});}}else{finish && finish();}})(0);},fail:function(res) {finish && finish();},});}比如官方WX-Downloader.js里这个cleanAllFiles,假如我把这个readdir改成从预存的csv中读取,效率能提高吗