I've been working on a mobile app in Visual Studio 2017, I need to do some file access but have struggled for the last week. what i have is:
function findCampaignFolders() {
alert("in find folder");
var fs = require('fs');
alert("finally past file system");
var Folders = fs.readdirSync("/Campagins");
var textString = "";
for (var i = 0; i < Folders.length; i++)
{
textString = textString + Folders[i];
}
alert(textString);
}
when this function is called alert("in find folder");
works and sends it promt.
but alert("finally past file system");
never fires or anything after.
the cordova is predicted with fs.readdirSync ()
so it recognized in the VS2017.
as for scripts load order in looks like in HTML file:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="scripts/platformOverrides.js"></script>
<script type="text/javascript" src="scripts/Objects.js"></script>
Objects.js is where my function lives.
If anyone can at least give me a hint as why i can't get this working or if there is another way i can go about it it would be a great help.
var fs = require('fs');
is Node.js code that doesn't work on Cordova apps. Node.js code is meant to be used on a server or on CLI apps, but not in client apps such as Cordova.
To read/write files in Cordova you have to use cordova-plugin-file
https://github.com/apache/cordova-plugin-file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.