Cannot removing file in ios using native path in native file plugin

Hello everyone,

I have native path like file:///var/mobile/Media/DCIM/100APPLE/IMG_0044.PNG. Now when I trying to remove that file using ionic native file(https://ionicframework.com/docs/native/file/) removeFile() then I am not able to remove. Even if I only resolving it by file.resolveLocalFilesystemUrl(pathofthatfile) i am getting error NOT_FOUND_ERROR.When I use file.resolveDirectoryUrl(“file:///var/mobile/Media/DCIM/100APPLE”) then this method resolve the directory and returns DirectoryEntry.

Another thing that is to notice is that when I share file using above same url then I able to share it. To share I am using ionic native Social Sharing plugin(https://ionicframework.com/docs/native/social-sharing/).

Can anyone know what is the problem???

Can I not delete files from iPhone using my ionic app??? Or Problem in any of plugins.

This is the my first question on forum, so if any mistakes in question please let me know.

Can you try below code?

let dirName = '100APPLE';
if (this.platform.is('android')) {
  dirPath = this.file.externalRootDirectory;
} else if (this.platform.is('ios')) {
  dirPath = this.file.documentsDirectory;
}
let filepath = dirPath + '/' + dirName + '/';
let fileName = 'IMG_0044.PNG';
file.removeFile(filepath, fileName);

Thanks for reply,
But I can’t use dirPath = this.file.documentsDirectory; because i am deleting images dynamically, so path can be any.

By the way, I handled it using creating my own plugin.

Hai bhardakishan,

I am also facing same issue while copying file form assets folder to externalRootDirectory. Its showing error like Not_Found. When i change extrernalRootDirectory to dataDirectory.

/* ********************************************************* */
/*                   Below Code is working fine              */
/* ********************************************************* */

const path = this.file.applicationDirectory + 'www/assets/';
		this.file.copyFile(path, 'mypdf.pdf', this.file.dataDirectory, 'mypdf.pdf').then(
			(fileCopyResp: any) => {
				console.log(fileCopyResp);
			},
			err => {
				console.log('Error over file copy:::\n', err);
			}
		);
/* ********************************************************* */
/*                   Below Code is not working               */
/* ********************************************************* */

const path = this.file.applicationDirectory + 'www/assets/';
		this.file.copyFile(path, 'mypdf.pdf', this.file.externalRootDirectory, 'mypdf.pdf').then(
			(fileCopyResp: any) => {
				console.log(fileCopyResp);
			},
			err => {
				console.log('Error over file copy:::\n', err);
			}
		);