# My first "SaveAs" package

#1

i am writing my first Atom package. I want to save my current editing file to another location. What i have written basically works. i can save the file. What i don’t like is that Atom will close the original file and open the new saved file.

I want to open my project folder and do with the files what needs to be done and simply with one click copy/save current open file to another location. Even after doing that i want to have my original project folder and original files open in Atom.

Can anyone help me with this?

Thank you.

Code:

  DownloadToController() {
let editor
editor = atom.workspace.getActiveTextEditor()

var remote = require('electron').remote;
var files = remote.dialog.showOpenDialog(remote.getCurrentWindow(), {properties: ['openDirectory']});
if(files && files.length) {
try{
editor.saveAs(files[0]+'\\'+editor.getTitle())
}
catch(err){
}
return files[0];
}
return null;
}


#2

I’m guessing that editor.saveAs() will always leave you with the file open at the new location. You should probably use the File API. It would look something like this:

file = new File(files[0]+'\\'+editor.getTitle())
file.write(editor.getText()).then( () =>
)


#4

Thak you for the answer. I tried out your suggestion. But i could not make it work

Picture

#5

#6

This is how i did it

DownloadToController() {
let editor
editor = atom.workspace.getActiveTextEditor()

var remote = require('electron').remote;
var files = remote.dialog.showOpenDialog(remote.getCurrentWindow(), {properties: ['openDirectory']});
if(files && files.length) {
file = new File(files[0]+'\\'+editor.getTitle())
file.write(editor.getText()).then( () =>
return files[0];
}
return null;


}

#7

I apologize, I didn’t explain fully enough. The File class has to be imported. This init.coffee script works:

{File} = require 'atom'