Software Archive
Read-only legacy content
17061 Discussions

Como Leer contenido de directorio(xdk/cordoba)

jaime_m_
Beginner
455 Views

hola cree un archivo de texto y lo grabe a traves de mi aplicacion en el directorio Dcim/Camera.

ahora quiero ller los archivos que se encuentran en ese directorio, por leer me refiero a listar el nombre de los archivos.

encontre una aplicacion que supuestamente hace eso pero el codigo no funciona , aqui esta

 

Read Contents of a File

Using FileEntry object we can read contents of a file. In the above code we saw how to get FileEntry object using DirectoryEntry object.

Here is the code to read content of the file we created

        document.addEventListener("deviceready", onDeviceReady, false);
        
        function onDeviceReady() 
        {
            requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess,onError);
        }
        
        function onSuccess(fileSystem) 
        {   
            var directoryEntry = fileSystem.root;
            
            directoryEntry.getFile("readme.txt", {create: true,exclusive: false}, function(fileEntry){
                //lets read the content of the file. 
                fileEntry.file(function(file){
                    //FileReader object streams the content of the file from storage disk to app
                    var reader = new FileReader();
                    reader.onloadend = function (evt) {
                        //result property is string type if you read data as string. If you read data as array buffer then its assigned to a array buffer object.
                        console.log(evt.target.result);
                    };
                    //to read the content as binary use readAsArrayBuffer function.
                    reader.readAsText(file);
                }, function(error){
                    console.log("Error occurred while readline file. Error code is: " + error.code);  
                });
                
            }, function(error){
                console.log("Error occurred while getting a pointer to file. Error code is: " + error.code);
            });
    
        }
        
        function onError(evt)
        {
            console.log("Error occurred during request to file system pointer. Error code is: " + evt.code);
        }

 

 

si aguien me puede ayuda de lo agradeceria, el plugins File esa agregado a mi app

 

saludos

0 Kudos
2 Replies
PaulF_IntelCorp
Employee
455 Views

I recommend you look at the following pages for help:

Mr. Raymond Camden has been involved in the Cordova and PhoneGap projects for a very long time and is very accomplished in the art of creating Cordova apps. His blogs contain very useful information.

0 Kudos
jaime_m_
Beginner
455 Views

thankyou but the example on the web no work for me

I don't know why

 

 

0 Kudos
Reply