I have an Ionic 4 / Cordova application using the File plugin, where I have some code similar to what I have in a test application here…
public async checkFile(): Promise<void> {
try {
await this.platform.ready();
const cord = <any>cordova;
if (cord.file == undefined) {
throw "Cordova file plugin not found, are cordova plugins included with the installer?";
}
const baseFolder: string = cord.file.dataDirectory; // On windows is "ms-appdata:///local"
console.log(`baseFolder: ${baseFolder}`);
const exits = await this.file.checkDir(baseFolder, "");
console.log(`exists: ${exits}`);
const dirEntries = [];
const entries: Entry[] = await this.file.listDir(baseFolder, "");
console.log(`files...`);
for (let entry of entries) {
console.log(entry.name);
dirEntries.push(entry.name);
}
} catch (error) {
console.error(JSON.stringify(error));
}
}
This used to work in Ionic 3 when I had an older version of the plugin. And it still works on Android, but on Windows I get the correct path (ms-appdata:///local) , and the call to checkDir
works, but now the this.file.listDir
always gives
{"code":1,"message":"NOT_FOUND_ERR"}
It still works on Android, and pretty sure it also does on iOS, but not on Windows.
I have tried file.listDir(baseFolder, “./”); and file.listDir(baseFolder, “.”); but neither work.
I will list my package.json below.
Does anyone have any idead how I can now get this to work on Windows (10)?
Thanks in advance!
package.json...
{
"name": "testfile",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "~8.1.2",
"@angular/compiler": "~8.1.2",
"@angular/core": "~8.1.2",
"@angular/forms": "~8.1.2",
"@angular/platform-browser": "~8.1.2",
"@angular/platform-browser-dynamic": "~8.1.2",
"@angular/router": "~8.1.2",
"@ionic-native/core": "^5.0.0",
"@ionic-native/file": "^5.15.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^4.7.1",
"cordova-android": "^8.1.0",
"cordova-plugin-file": "^6.0.2",
"cordova-windows": "^6.0.1",
"core-js": "^2.5.4",
"rxjs": "~6.5.1",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/architect": "~0.801.2",
"@angular-devkit/build-angular": "~0.801.2",
"@angular-devkit/core": "~8.1.2",
"@angular-devkit/schematics": "~8.1.2",
"@angular/cli": "~8.1.2",
"@angular/compiler": "~8.1.2",
"@angular/compiler-cli": "~8.1.2",
"@angular/language-service": "~8.1.2",
"@ionic/angular-toolkit": "~2.0.0",
"@types/jasmine": "~3.3.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "^5.0.0",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^4.1.2",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.1.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~2.0.1",
"karma-jasmine-html-reporter": "^1.4.0",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.15.0",
"typescript": "~3.4.3"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"cordova-plugin-file": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-statusbar": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-ionic-keyboard": {}
},
"platforms": [
"windows",
"android"
]
}
}