Hi everyone!
I'm a bit of a noob at this, but does anyone know how I might import a ".txt" file, or ".rtf" etc. as a string into a custom module?
I'm basically looking to do something like:
f = open("D:\....string_articulations.txt", "r")
print(f.read())
Thanks!
Note that you'll need to write nativeRequire('fs')
instead of require('fs')
.
I keep getting this:
TypeError: Cannot read property 'readFile' of null
error.
I don't know why it is..
fs = require('fs');
fs.readFile('Test.txt', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
When I put
fs = nativerequire('fs');
It spit out this error:
ReferenceError: nativerequire is not defined
Ok, I think I'm getting somewhere. It's showing a "submodule not found" for fs
(ERROR) Submodule not found: D:\SNS Work Folder\Open Stage Control Touch Interface\OSCMZ-0419\MZ Show instrument name version\fs
UGHHHH I'm an idiot
I think I've fixed it...
Needed to capitalize "nativeRequire"
Oh boy, the joys of being a noob.. haha
Ok, I have no idea why this isn't working:
fs = nativeRequire('fs');
var string_articulations = fs.readFile('D:/_GOD TEMPLATE/Athena v1.2 for Bear/string_articulations', 'utf8',function (err, data) {
if (err) throw err;
//console.log(data.toString());
});
console.log(string_articulations);
it spits out "undefined" for the strings_articulations variable
Ok, once again, learning a lot here, I needed:
fs.readFileSync()
Learning a lot here, hopefully someone else gets something out of this haha.
1 Like