2

I'm on Windows 10, trying to read and write a simple text file using Tabris.js

console.log reports:

/local/src/hello.txt
Error: No such file or directory: /local/src/hello.txt

CODE:

const {fs} = require('tabris');

let path=fs.filesDir + '/src/hello.txt'
console.log(path)

fs.writeFile(path, 'Hello World!', 'ascii')
.then(() => console.log('file written:', path))
.catch(err => console.error(err));

Tabris.js reference:

Clarification:

If I get this to work, I'm going to do a very simple tutorial.

Tabris runs fine with no issues, but I can't read or write a file because of the error finding the file. I've tried a dozen combinations of things, with dots, no dots etc. - no luck. Tried __directory, fs.filesDir etc. so path wouldn't be hard coded, nothing working.

Tabris folders and file location:

C:\Users\Rob Acer Aspire 3\junk\package.json
C:\Users\Rob Acer Aspire 3\junk\src\app.js

Tabris 2.4

Thanks for all the help.

UPDATE- got it working...

It seems to work now, with code below. I was assuming that hello.txt would be in my /src folder, or at least me tabris folder called 'junk' but it is writing to another folder. It seems that the docs are correct on this as they say The path of a directory that the app may use to store persistent files.

  let file = fs.filesDir + '/hello.txt';
  //  ok, this works.. > file written: /local/hello.txt
  // and is located in:
  // C:\Users\Rob Acer Aspire 3\AppData\Local\Packages\EclipseSource.Tabris.js2_en185yn5qwkmw\LocalState\hello.txt

I didn't understand what /local/hello.txt really meant

So, my question is answered, thanks for help.

Rob

mrmccormack
  • 143
  • 1
  • 10
  • I posted an answer based on what I can see in your question. If the answer doesn't help, what is the actual directory you are trying to read from in windows form? – SteveB Mar 24 '18 at 15:50
  • hey thanks.... still now working with the ."./local/src/hello.txt" - actual directory on windows 10 is: C:\Users\Rob Acer Aspire 3\junk\src\hello1.txt - junk folder was created using ` tabris init` – mrmccormack Mar 24 '18 at 18:29
  • That directory would be "./users/Rob Acer Aspire 3/junk/src/hell1.txt" but you should use a relative location to your code so what directory is your code running in? – SteveB Mar 25 '18 at 00:02
  • I'll add clarification to original question. but I can't get it working with any path... i.e. event this generates error: Error: No such file or directory: ./users/Rob Acer Aspire 3/junk/src/hello.txt at createError (./node-modules/tabris/tabris.min.js:1:69264) I've tried different files like hello1.txt, hello.txt etc. – mrmccormack Mar 25 '18 at 13:44
  • mrmccormack, Could add this as an answer and mark it as accepted? That way the question shows up as resolved – Cookie Guru Mar 29 '18 at 07:56

2 Answers2

0

On windows

"/local/src/hello.txt 

would be the equivalent of

"c:\local\src\hello.txt"

In order for the path to start within your application directory, you should star the path with a "./" for current application directory so in your case

"./local/src/hello.txt" 

If you want to go back one directory, you would start with a "../"

SteveB
  • 894
  • 7
  • 15
0

It works now, with code below. I was assuming that hello.txt would be in my /src folder, or at least me tabris folder called 'junk' but it is writing to another folder. It seems that the docs are correct on this as they say:

The path of a directory that the app may use to store persistent files.

  let file = fs.filesDir + '/hello.txt';
  //  ok, this works.. > file written: /local/hello.txt
  // and is located in:
  // C:\Users\Rob Acer Aspire 3\AppData\Local\Packages\EclipseSource.Tabris.js2_en185yn5qwkmw\LocalState\hello.txt

I didn't understand what /local/hello.txt really meant

mrmccormack
  • 143
  • 1
  • 10