Set NWjs Open File Dialog Path

0 favourites
  • 7 posts
From the Asset Store
10 Orchestral Soundtracks / ~2 mins each / 11 audio clips in total
  • Does anyone know a way to set the NWjs Open File Dialog path, so that the dialog opens in a particular folder?

    What for...? I would like to establish a database for game-save objects and would like the player to select one for import (or navigate to somewhere else on their drive, if they wish). The default game-save folder will be buried in a not-easy-to-find folder at c:\Users\Name\GameTitle\Data - thus I would like the File Dialog to open in the Data folder if possible. There's some info on GitHub but I don't see a way to achieve this through c2.

    Is this possible or am I just dreaming....?

    Thanks.

  • Edit - I had a thought - I could use the Browser Object to open a window at the save location URL, for the player to then drag/drop the file into the NWjs window. This is a solution, but I consider it a bit untidy as the rest of the game uses Open dialog windows (no drag/drop), but using this will be better than nothing if no other solutions can be found.

  • Use the browser object to execute some javascript:

    "document.getElementById('c2nwOpenFileDialog').setAttribute('nwworkingdir', 'your path goes here');"

    That will set the open file path.

    Make sure it is before you call to open the file dialog.

    note: you may want to use the application path or user path provided by the nw.js object expression, to ensure it is correct across all platforms (mac,windows,linux).. since the path will be different for each I think.

    edit: I think the app/user path from nw.js object only work when project is exported.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Prominent - thank you very much! However, I cannot get it to work in my W10... Both export and preview give similar problems. I put the variable NWjs.UserFolder in the "your path goes here" position (capx) but the open dialog location is incorrect (I am not sure if the apostrophes are required, but with or without them results in an incorrect location being opened).

  • Sorry to bring this back from the dead, but Colludium, did you ever get this to work?

  • - sorry to say that I gave up because I couldn't figure a way of setting the opening folder dialog. Instead I opted for asking the player to drop a file into the game window instead. Won't work for kiosk mode though!!

  • Yeah file dropping is what I've settled on for now too, thanks

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)