appcelerator retrieve all files from directory

做~自己de王妃 提交于 2019-12-24 06:45:24

问题


im working on an Ipad paint application and i want to retrieve all files from a specific directory, and delete the last saved image. In the appcelerator simulator it all works perfect, but when i run my application on my ipad it stops at var fid = dfo.getDirectoryListing(); I don't know what i'm doing wrong because i know he saves the png files in the test folder on ipad (tested it with alert).

    //going to the folder, this works he shows alert
   var dfo = Titanium.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory + '/test');
        alert(dfo);
        //trying to get all the files, this works on emulator he shows all files. on ipad empty alert
    var fid = dfo.getDirectoryListing();
        alert(fid);
        //application stops here
    fid = fid.splice(1, fid.length - 1);
        alert(fid);
    var lengte = fid.length - 1;

if (lengte != -1) {
    var lengte2 = lengte -1;
     painter.clear();
     painter.setBackgroundImage(parent + '/back.png');
    painter.setBackgroundImage(parent + '/test/' + fid[lengte2]);
    var file = Titanium.Filesystem.getFile(parent + '/test/' + fid[lengte]);
    file.deleteFile();
}
else{
  alert('going back is at his end');
     painter.clear();
     painter.setBackgroundImage(parent + '/back.png');

}

I hope someone can help me, thanks in advance!


回答1:


you should be saving your files to Ti.Filesystem.applicationDataDirectory not the resources directory.

I think the emulator is allowing it, but the device is not for security reasons..



来源:https://stackoverflow.com/questions/5457549/appcelerator-retrieve-all-files-from-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!