0

Using the fileSaver module on gitHub, I can save a file using the following code:

var file = new File([data], "jData" + timestamp + ".txt", {type: "text/plain;charset=utf-16"});
saveAs(file);

The Issue

Over time the archived files look messy in the download folder. Is there a way to make the text files nest in a single folder?

if i do:

 var file = new File([data], "myArchive/jData.txt", {type: "text/plain;charset=utf-16"});

Then the saved file is the whole string. I am a bit new to the fileSaver and I could use some guidance with saving file in to specific folders and directories.

Solution seeking:

  • Is it possible to save the file inside of a folder within the project scope?
  • How can I save the file in to an already existing folder?
  • When I use "jData.tx"(without the timestamp), the file saver will create a copy file.

    Example: "jData(2).txt", "jData(3).txt", "jData(3).txt" ,etc.

  • Is there a way to overwrite the same file each time, instead of creating copies?
  • Is there another gitHub repository besides the one I am using that can do what I am asking.
MrEhawk82
  • 811
  • 2
  • 13
  • 22
  • `"Is it possible to save the file inside of a folder within the project scope?"` => What does this mean? In what sense does "the project's scope" exist on the user's file system? – 1252748 Jan 13 '20 at 01:24
  • `"Is there a way to overwrite the same file each time, instead of creating copies?"` => Are you asking if you can write client-side javascript that will overwrite files on a user's file system? No way. – 1252748 Jan 13 '20 at 01:26
  • first comment re: yes, save it to a folder already specified in my projects' repository. – MrEhawk82 Jan 13 '20 at 02:09
  • second comment re: I'm not sure exactly. Is it possible to just delete the file each time before creating a new one? It would seem like an overwrite, but it would actually be a delete and replace type thing. – MrEhawk82 Jan 13 '20 at 02:10
  • another workaround i was thinking was to still save to the downloads folder, but make the files store in a folder.. – MrEhawk82 Jan 13 '20 at 02:14
  • If this is a node script or an electron app you could do it, but if it’s just running in a browser you cannot alter a user’s file system. – 1252748 Jan 13 '20 at 03:23
  • npm already init'd. I can install a node module, but i don't know how to use it in my javascript file. – MrEhawk82 Jan 13 '20 at 06:07
  • If I understand correctly, you have a project at, say `/Users/MrEhawk82/Documents/project-repository/`, and in that repository is code for a webpage you wish to trigger a download that will not go into `/Users/MrEhawk82/Downloads`, but into the project directory. Is this correct? – 1252748 Jan 13 '20 at 15:26
  • If you have installed `file-saver` using NPM, you can either include it in an html page with a script tag ` – 1252748 Jan 13 '20 at 15:28

1 Answers1

0

It is not a good practise to specify download paths because the information to a specific folder path is real which may pose security threat.

Check out this link Get browser download path with javascript

Hope it helps.