Pick File (like atom.pickFolder())


I need atom.pickFolder() for file.
Is there a possibility?


Calling just atom.open() will open the standard file open dialog for the system.


Thanks, but i need the file-path. With a callback function like atom.pickFolder(function (paths) {}).
atom.open just open the selected file in new text editor.


But atom.open() returns a Promise that resolves to the TextEditor opened, from which you can get the path.

If you need the path but not the file opened … then yeah, there isn’t anything right now that I know of.


Okay, i programmed a (workaround-) pickFile:
I hope there will be a atom.pickFile function in the next Atom Versions.

  pickFile: (callback) ->
    prePaneURI = atom.workspace.getActivePaneItem().getURI()
    preTabLength = atom.workspace.getPaneItems().length
    disposeItem = atom.workspace.onDidOpen (event) -> #on select file
      callback event.uri
      if atom.workspace.getPaneItems().length>preTabLength
        event.item.destroy() #close tab, if tab is new
      else #open pre. tab
        atom.workspace.open prePaneURI
      disposeItem.dispose() #to run only once after atom.open


Is it really atom.open() or is it atom.workspace.open() ?

Checking the documentation, only the later appears to return a Promise. Or am I missing something?


Yes he means atom.open().
It will open a file picker and after file choose it use atom.workspace.open().
You could not prevent atom.workspace.open(). This is my Problem.

For this purpose, there is nothing in the documentation.

My code and the idea previously also not work as well.

This (my) package modal-file-manager is currently enough for me.
But I would be very happy about a good OS File picker.


Use remote module of electron like this:

function pickFile() {
    var remote = require('electron').remote;
    var files = remote.dialog.showOpenDialog(remote.getCurrentWindow(), {properties: ['openFile']});
    if(files && files.length) {
        return files[0];
    return null;


Wow. That works. Thanks!