Code to change files?

Fill this out this info to make it easier for the community to help you! If you don’t fill out this information, your post may be deleted or removed.

What Wick Editor Version are you using?
1.19

Describe the Problem
Hey is there a code to change files? For ex. If I click a button another file in my pc will open ( sorry If this question is stupid)

What have you tried so far?
I did browse through some codes but didn’t understand which one

hi, i don’t quite understand what you mean by this. do you mean you want to open a prompt which allows the user to select a file, or do you want the wick project to change into another one? (i am uncertain of its possibility)

i think he means that clicking a button on a wick project will open a file on the computer. for example, if i press some button, it opens a file called boringPaper.txt or something.

You can use the following script for writing to a .txt:

function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}

// Start file download.
download("file.txt","Contents go here");

And if you want to write to a .json you can use this script:

function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}

// Start file download.
download("file.json","Contents go here");

Example here: Export File.wick (2.7 KB)

in the example, they both export a txt.

Oops
I changed it to json