Pick File (like atom.pickFolder())


#1

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


#2

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


#3

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.


#4

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.


#5

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
    atom.open()

#6

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?


#7

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.


#10

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;
}

#11

Wow. That works. Thanks!