像DOS的tree命令一样遍历文件夹及文件,为何显示的不对?
没办法上传图片,大家看看代码吧,手机测试的结果和实际的不符。
当然,代码是我从java程序中移植过来的,是可以正常使用的,布置为何这里就不行了,如何修正程序?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<style type="text/css">
#c{ font-family: "Courier New";}
</style>
</head>
<body>
<div id='c'></div>
<script type="text/javascript">
var DEEP=32;
//用于控制显示树形结构的连接线
var ls=new Array(DEEP);
for(var i=0;i<ls.length;++i)ls[i]=false;
function getPrefix(level){//显示每行内容的前缀
var s="";
for(var i=0;i<level;++i) s+= ls[i]?"│":" ";
return s;
}
var sortByName=function(a,b){
return a.name==b.name?0:(a.name>b.name?1:-1);
};
var o=document.getElementById("c");
function show(m){
o.insertAdjacentHTML("beforeEnd","<br>"+m);
}
function showSubForlder( entry, level){
if(level>=DEEP)return; //超过指定深度,不予处理
entry.createReader().readEntries(function(es){
var fs=[];
var ds=[];
for(var i=0;i<es.length;++i){
if(es[i].isFile)fs.push(es[i]);
else ds.push(es[i]);
}
fs.sort(sortByName);
ds.sort(sortByName);
ls[level]=ds.length>0;
if(fs.length>0){//有文件,则显示文件名
var pre=getPrefix(level+1);
for(f in fs)show(pre+fs[f].name);
show(pre);
}
for(var i=0;i<ds.length;++i){//有目录,则显示目录名并递归
if(i==ds.length-1) ls[level]=false;
show(getPrefix(level)+(ls[level]?"├":"└")+ds[i].name);
showSubForlder(ds[i],level+1);//递归处理子目录
}
},
function ( e ) {
alert( "Read entries failed: " + e.message );
})
}
// 扩展API加载完毕后调用onPlusReady回调函数
document.addEventListener( "plusready", onPlusReady, false );
// 扩展API加载完毕,现在可以正常调用扩展API
function onPlusReady() {
// var p=plus.io.convertLocalFileSystemURL("_www/index.html");
// alert(p);
plus.io.resolveLocalFileSystemURL( "_www", function( entry ) {
show(entry.name);
showSubForlder(entry,0);
}, function ( e ) {
alert( "Resolve file URL failed: " + e.message );
} );
// var env=plus.android.importClass("Enviroment");
// alert(env);
}
</script>
</body>
</html>
3 个回复
风云 (作者)
IO模块管理本地文件系统虽然很方便(可直接应用于Android及ios),但确实存在致命的问题,应该是不能同步操作造成的。
这里用 Native.js 完美解决了问题,但是针对Android及ios,需要不同的解决方法,这是美中不足的地方。
风云 (作者)
附一个手机的二级目录结构:
/
├nvdata
├sdcard
│├moji
│├Mob
│├Fonts
│├Android
│├Download
│├ispdbg
│├msc
│├Music
│├360
│├Pictures
│├Movies
│├DCIM
│├Customize
│├baidu
│├backups
│├Ringtones
│├backup
│├data
│├FlymeTelecom
│├autonavi
│├amaplocationapi
│├tencent
│├Qmap
│├Adview
│├com.meizu.gslb
│├ExtDataTunnel
│├emlibs
│├ShareSDK
│├mz_browser_crash_log
│├FlymeWallpaper
│├VideoCache
│├libs
│├system
│├PimMsgCache
│├com.jootun.hudongba
│├traces
│├Recorder
│├linked-joyrun
│├hudongba
│├bddownload
│├Readphone
│├Books
│├Sdk
│├amap
│├smarun
│├meizunetsearch
│├documents
│├image
│├shading_otp
│├co.runner.app
│├mfcache
│├PowerDump
│├setup
│├lifedoc
│├mtklog
│├apsamapapi
│├PlugIReader
│└httpcache
├custom
│├lost+found
│├3rd-party
│├app
│└plugin
├persist
├protect_s
├protect_f
├storage
│├sdcard0
│├sdcard1
│├emulated
│└usbotg
├config
├cache
├acct
│├uid_10145
│├uid_10051
...
│├uid_1037
│└uid
├vendor
│├etc
│├lib
│└lib64
├d
│├spm
│├cpuhvfs
│├swp_emulate
│├asoc
│├binder
│├hid
│├cpuidle
│├musb-hdrc
│├mmc1
│├mmc0
│├mali
│├ged
│├ccmni
│├displowpower
│├disp
│├ion
│├memblock
│├extfrag
│├dynamic_debug
│├tracing
│├ieee80211
│├iio
│├usb
│├m4u
│├dma_buf
│├regmap
│├bdi
│├regulator
│└pinctrl
├etc
│├appwidget
│├audio_param
│├bluetooth
│├dhcpcd
│├firmware
│├fmr
│├lucid
│├mddb
│├permissions
│├ppp
│├radvd
│├security
│├wide-dhcpv6
│└wifi
├mnt
│├sdcard2
│├sdcard
│├cd-rom
│├obb
│├asec
│├secure
│├media_rw
│└shell
├system
│├lost+found
│├MzApp
│├app
│├bin
│├customizecenter
│├data
│├etc
│├fonts
│├framework
│├lib
│├lib64
│├media
│├plugin
│├priv-app
│├res
│├tts
│├usr
│├vendor
│└xbin
├sys
│├fs
│├bus
│├dev
│├devices
│├block
│├class
│├power
│├firmware
│├kernel
│├mtk_rgu
│├module
│├mtuart
│└bootinfo
├sbin
├res
├proc
│├mtk_battery_cmd
│├eem
│├picachu
│├cpufreq
│├lk_info
│├perf_ux
│├mt_power_gs
│├mali
│├atf_log
│├xlog
│├wmt_tm
│├mobile_tm
│├mtktz
│├mtkcooler
│├cmdq_test
│├mtk_sched
│├mtprof
│├aed
│├hps
│├pbm
│├gpufreq
│├cpu_ss
│├clkmgr
│├uid_stat
│├mt_pmic
│├asound
│├scsi
│├mtk_cmdq_debug
│├chip
│├pm_init
│├freqhopping
│├ppm
│├irq
│├sys
│├bus
│├tty
│├driver
│├fs
│├net
│├self
│├1
│├2
│├3
│├4
│├5
│├7
...
│├31764
│├32074
│└32289
├data
├root
└dev
├radio
├usb-ffs
├pipes
├fscklogs
├cpuctl
├memcg
├snd
├block
├log
├input
├graphics
├socket
└pts
风云 (作者)
还发现一个问题,IO模块管理本地文件系统:
对于Android手机,可以遍历所有目录,
而对于ios,则只能在应用内遍历,
是不是这样子呢?请专家们回答一下呀!谢谢...
回梦無痕
iOS只能访问应用内目录和共享目录
2017-08-28 18:01
风云 (作者)
谢谢啦哈~~~
2017-08-29 09:45