Work with path returned from showOpenDialogue


lastIndexOf() doesn’t work with the path returned from showOpenDialog on the render side. Casting it to a literal with .toString() doesn’t help.

For example:

        FilePath = dialog.showOpenDialog({ filters: [{name: 'text', extensions: ['txt']}], properties: ['openFile']})[0];
        FilePath = FilePath.replace(/[\\]/g, "/");

Interestingly, lastIndexOf doesn’t work after “FilePath = FilePath.replace(/[\]/g, “/”)” either. What is returned from “showOpenDialogue()”, exactly?


According to the documentation:

On success this method returns an array of file paths chosen by the user, otherwise it returns undefined.


I figured it out. I didn’t understand that the dialog calls return Node
path objects. Thanks.