question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to save file to specific directory

See original GitHub issue

Moving over from https://github.com/electron/electron/issues/7065 /cc @disc9562


  • Electron version: 1.3.4

  • Operating system: Windows 8.1 I am using spectron to test my app. I am opening dialog in my app like this:

    ipc.on('open-directory-dialog', (event, arg) => {
    
    let returnValue = function(directory) {
    
    if (typeof directory !== 'string') {
    
      directory = directory[0]
    }
    event.returnValue = directory
      }
      let options = {
        properties: [
         'openDirectory'
       ]
     }
      if (process.platform !== 'darwin') {
         dialog.showOpenDialog(options, (directory) => {
           if (directory) {
             returnValue(directory)
          }
    })
    return
      }
    returnValue(dialog.showOpenDialog(BrowserWindow.fromWebContents(event.sender), options))
    

And I want to auto select directory in test. I am using preload to do that. But it will make my app crash.

//preload
if (process.env.RUNNING_IN_SPECTRON) {
      dialog.showOpenDialog = (opts, cb) => {
        if (opts.title === 'open-directory-dialog') {
          cb(['C:/Users/user/Desktop/']);
          }
       };
   }

Any ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MarshallOfSoundcommented, Sep 9, 2016

It isn’t the const that makes it work. The old code was trying to call undefined as a function and all sorts of other dodgy things.

This is just correct code 👍

Closing this out as the original question / issue has been resolved 👍

1reaction
MarshallOfSoundcommented, Sep 8, 2016

@disc9562 I have a PoC for adding electron-test-utils bindings to Spectron, but until that I’ll just fix your mocking function 👍

//preload
const paths = ['C:/Users/user/Desktop/'];

if (process.env.RUNNING_IN_SPECTRON) {
   dialog.showOpenDialog = (opts, cb) => {
     if (opts.title === 'open-directory-dialog') {
       if (cb) cb(paths);
       return paths;
     }
  };
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to save file/s to a specific directory? - Help
Hi! I have this task where I need to save file/s to a specific folder. Unfortunately, the path where I need to save...
Read more >
HOW TO SAVE FILES IN FOLDERS
If you right click on the file then on Save as you can tell it where to save it. You should have a...
Read more >
How to Save a Directory List in DOS
To get the complete directory tree with subdirectories and files, type dir /s, then press Enter. You will see the contents of the...
Read more >
Is there a way to save a file to a specific folder inside your ...
Just pass the desired file path to the file argument. write.csv(data, file='output/data.csv'). 2 Likes.
Read more >
How to save a file to a specific directory in python?
As long as you have access to the directory you can simply change your file_name.pdf' to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found