0

I try to write a log file using IONIC2, all seems to work, not error, with IONIC2 the file exist the directory is created, but I can not see the file with a file explorer. See my source there :

            File.checkDir(cordova.file.externalDataDirectory, 'mydir')
                .then(_ => {
                    trace.info('yay')
                })
                .catch(err => {
                    trace.error('BackgroundGeolocationService','constructor',`boooh`);
                    File.createDir(cordova.file.externalDataDirectory, "mydir", false)
                        .then(function (success) {
                            // success
                            trace.info('create mydir success');
                        }, function (error) {
                            // error
                            trace.error('BackgroundGeolocationService','constructor',`unable to create mydir`);
                        }.bind(this));
                });


            File.createFile(cordova.file.externalDataDirectory, "new_file.txt", true)
                .then(function (success) {
                    // success
                    trace.info('write file success');
                }, function (error) {
                    // error
                    trace.error('BackgroundGeolocationService','constructor',`error:${error}`)
                });
Patrice Rolland
  • 49
  • 2
  • 11

1 Answers1

0

Your source checks for a folder called myDir being created, but when you create new_file.txt, it isn't creating it in the myDir folder, it looks to be creating it in the externalDataDirectory folder.

So check the externalDataDirectory folder rather than your myDir folder, and you'll probably see your file there.

Andrew Berry
  • 853
  • 3
  • 10
  • 25
  • I look in every directory of my mobile the file and the directory doesn't exist. – Patrice Rolland Nov 22 '16 at 08:20
  • Try using externalRootDirectory for now. It should just appear in the root of your device. Just want to see if it's an issue of permissions viewing the folder, rather than an issue of the file not actually writing. – Andrew Berry Nov 22 '16 at 09:10
  • i see the created file "new_file.txt" and directory "mydir" on a file manager on my mobile but not on my computer via windows file explorer ! – Patrice Rolland Nov 22 '16 at 10:37
  • Refer to the documentation: https://github.com/apache/cordova-plugin-file Windows doesn't support the use of externalRootDirectory, so create a merge file and specify a different location for windows builds. You'll most likely use dataDirectory instead – Andrew Berry Nov 22 '16 at 10:40
  • If I restart my mobile I see the files ! I found this on http://stackoverflow.com/questions/28369123/cordova-created-files-not-showing-in-windows-explorer-unless-restart-of-device – Patrice Rolland Nov 22 '16 at 12:37
  • if I plug and unplug my mobile I see the files too :) – Patrice Rolland Nov 22 '16 at 15:53