Deleting all files from the cache folder in ionic code example

Example: Deleting all files from the cache folder in ionic

this.file.listDir(this.file.cacheDirectory,'org.chromium.android_webview').then((result)=>{

            console.log('files in org.chromium.android_webview directory: ', result);

            console.log('Started deleting files from cache folder!');

            for(let file of result){

                if(file.isFile == true){

                    this.file.removeFile(this.file.cacheDirectory+'/org.chromium.android_webview/', file.name).then( data => {
                        console.log('file removed: ', this.file);
                        data.fileRemoved.getMetadata(function (metadata) {
                            let name = data.fileRemoved.name;
                            let size = metadata.size ;
                            let fullPath = data.fileRemoved.fullPath;
                            console.log('Deleted file: ', name, size, fullPath) ;
                            console.log('Name: ' + name + ' / Size: ' + size) ;
                        }) ;
                    }).catch( error => {
                        file.getMetadata(function (metadata) {
                            let name = file.name ;
                            let size = metadata.size ;
                            console.log('Error deleting file from cache folder: ', error) ;
                            console.log('Name: ' + name + ' / Size: ' + size) ;
                        }) ;
                    });

                }
            }
        }) ;

Tags:

Misc Example