1

It works properly when I run the same code locally using Electron JS.

var dir = './test-new-folder'; // OR var dir = 'test-new-folder';

if (!fs.existsSync(dir)) {
   fs.mkdirSync(dir, '0777', true);
}

The above code works properly in my local and creates a folder named 'test-new-folder' inside my root folder.

But after creating it's desktop application on MAC,

  1. Why this code doesn't work? Why doesn't it create 'test-new-folder'? What could be the work around for this?

  2. Also I want to track/get all the data which will be pushed in this newly created folder! Can I get such events? Or any suggestions for this?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Aniruddha Shevle
  • 4,602
  • 4
  • 22
  • 36

1 Answers1

0

As suggested by @lawrence Cherone in the comments, I've followed this: electronjs.org/docs/api/app#appgetpathname

And the solution I've got is below,

var desktopPath = (electron.app || electron.remote.app).getPath('desktop');

var dir = desktopPath + '/test-new-folder';

if (!fs.existsSync(dir)) {
   fs.mkdirSync(dir, '0777', true);
}
Aniruddha Shevle
  • 4,602
  • 4
  • 22
  • 36