Work with path returned from showOpenDialogue


#1

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, "/");
        alert(FilePath.lastIndexof("/"));

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


#2

According to the documentation:

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


#3

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