Unable to delete pdf file from ios memory using nativescript


#1

source code
service.ts

 filename: string = "testagreement.pdf";
    private folder: fs.Folder = fs.Folder.fromPath(fs.path.join(fs.knownFolders.documents().path, "Signet_NDAAgreements"));
   public removepdf(key: string) {
        const file = this.folder.getFile(`${key}.pdf`);
        alert(file);
        return file.remove();
    }

component.ts

   this.ndaagreementservice.removepdf("testagreement.pdf").then((res) => {
                alert("in delte NDA");
                console.log(res);
                } ,
            error => {
                alert(error);
            });

#2

Your code produces testagreement.pdf.pdf, double check whether your path is correct.


#3

you are right…after modifying the argument in component.ts

the logs says this:

CONSOLE LOG file:///app/services/NDA-Agreement.service.js:38:20: {
“_path”: “/var/mobile/Containers/Data/Application/A954D3C2-6809-472F-ADAD-676E5E7FDB93/Documents/Signet_NDAAgreements/testagreement.pdf”,

“_name”: “testagreement.pdf”,

“_extension”: “.pdf”

}

component.ts …modified code

 this.ndaagreementservice.removepdf("testagreement").then((res) => {
                alert("in delte NDA");
                console.log(res);
                } ,
            error => {
                alert(error);
            });

#4

It is not any error…but after doing this operation if i try to fetch the pdf file from same path…it does fetches…it should actually throw an error…


#5

You should use exists method to see if file exists already. When you do getFile, a file entry will be created if not exists.


#6

ok thanks for helping in debugging…it is working for me now…actually the folder path was not correct