Using JS, this cannot be done. If your trying to download a file to specific destination in the drive it is not possible. This possess a huge security risk if browsers allow it.

When a user is viewing a website, they are using a browser to access the webpage and browser decides what all permissions a website can have and what limitations it should put.

The only way that you download a file in specific folder is,the user doing to himself. Otherwise downloads made by browser will be stored at some default destination like /user/Downloads or user chosen path /user/Downloads/Chrome_Downloads.

Answer from Shahed on Stack Overflow
🌐
Quora
quora.com › How-can-I-code-in-JavaScript-to-download-my-files-to-a-specific-folder-where-I-want-to-save
How to code in JavaScript to download my files to a specific folder where I want to save - Quora
Answer (1 of 2): Short answer: You can’t. Long answer: Again, you can’t. I am not sure what you are trying to do here but I am assuming you are writing a script which will enable a browser user to click on one link and get a number of files downloaded, and that too to a local directory.
Discussions

[Javascript} Can I specify the download directory when using the "download" function?
This isn't possible as it is controlled by the browser. There's the new File System Access API but that is likely not what you want. If you want to have the user download a specific folder structure or name, have them download a zip file since when they unzip it, you can control the folder structure and file locations relative to each other. More on reddit.com
🌐 r/learnprogramming
1
1
September 4, 2022
javascript - Download A File At Different Location Using HTML5 - Stack Overflow
I am downloading files using HTML5 from below codes that you can see live in action at JSBIN HTML5 Download File DEMO and its working perfectly file and downloading my files at my browser default More on stackoverflow.com
🌐 stackoverflow.com
Javascript download an on-the-fly generated BLOB file into specific folder - Stack Overflow
So I'm trying to write a Firefox Webextension. I want to save title, url and a personal comment of a webpage into a file, myfile.txt Here it is what I came to: I don't want my Downloads folder to ... More on stackoverflow.com
🌐 stackoverflow.com
February 11, 2017
javascript - Download to a particular folder from a web application - Stack Overflow
I have a web application, I have a requirement to download more than 10 files to a folder. By default the download happens to browser download location. The user have a new requirement to have an o... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
gist.github.com › tanaikech › 38b536923b1765da052c21aab093649d
Downloading Files Under Specific Folder using Node.js · GitHub
Change the SCOPE from var SCOPES ...eadonly'];. Run script, retrieve the code and authorize. function listFiles(auth) { var folderid = "### folder ID ###"; // Folder ID....
🌐
Reddit
reddit.com › r/learnprogramming › [javascript} can i specify the download directory when using the "download" function?
r/learnprogramming on Reddit: [Javascript} Can I specify the download directory when using the "download" function?
September 4, 2022 -

In the example below, is there an option I can add to specify the download directory?

Currently the file saves to my (browser's) default download location (desktop).

But I want the file to save to the same folder as the index.html file.

Thank you.

<!doctype html>


<a href="" id="downlink" download="">Download me</a>



<script>

    function download(file) {
        let link = document.getElementById("downlink");
        link.setAttribute("download", file);
        link.click()
    };

    download("text.txt");

</script>

source

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › API › downloads › showDefaultFolder
downloads.showDefaultFolder() - Mozilla - MDN Web Docs
July 17, 2025 - Toggle sidebar · Mozilla · Add-ons ... · Learn more · Deutsch · English (US) Français · The showDefaultFolder() function of the downloads API opens the default downloads folder in the platform's file manager....
Top answer
1 of 2
25

It's not possible because this poses a security risk. People use fairly real information for their folder structure and accessing the folder names in itself poses an immediate risk. As described here:

Get browser download path with javascript

Most OSs tend to just default to a Download location and this is something the user decides through the Browser they use. Not the website.

In Chrome, Download location setting can be found at chrome://settings/downloads

2 of 2
11

This is now possible in most Chromium based desktop browsers (and safari soon), using the File System Access API. https://caniuse.com/native-filesystem-api

An example on how to do this can be found here: https://web.dev/file-system-access/#create-a-new-file

Something along the lines of:

async function getHandle() {
  // set some options, like the suggested file name and the file type.
  const options = {
    suggestedName: 'HelloWorld.txt',
    types: [
      {
        description: 'Text Files',
        accept: {
          'text/plain': ['.txt'],
        },
      },
    ],
  };

  // prompt the user for the location to save the file.
  const handle = await window.showSaveFilePicker(options);

  return handle
}

async function save(handle, text) {
  // creates a writable, used to write data to the file.
  const writable = await handle.createWritable();

  // write a string to the writable.
  await writable.write(text);

  // close the writable and save all changes to disk. this will prompt the user for write permission to the file, if it's the first time.
  await writable.close();
}

// calls the function to let the user pick a location.
const handle = getHandle();

// save data to this location as many times as you want. first time will ask the user for permission
save(handle, "hello");
save(handle, "Lorem ipsum...");

This will prompt the user with a save file picker where he can choose a location to save the file to. In the options, you can specify a suggested name and the file type of the file to be saved.

This will return a file handle, which can be used to write data to the file. Once you do this, the user is asked for write permission to the created file. If granted, your app can save data to the file as many times as you like, without re-prompting the user, until all tabs of your app are closed.

The next time your app is opened, the user is prompted for permission again, if you use the same file handle again (the handles can be saved in IndexedDB to persist them across page loads).

The File System Access API also allows you to let the user pick an existing file, for your app to save later. https://web.dev/file-system-access/#ask-the-user-to-pick-a-file-to-read

🌐
Stack Overflow
stackoverflow.com › questions › 36061448 › download-to-a-particular-folder-from-a-web-application
javascript - Download to a particular folder from a web application - Stack Overflow
The user will be searching with some condition and all files which match the condition should be downloaded to the folder given by user.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 31590944 › download-file-in-a-specific-folder
javascript - download file in a specific folder - Stack Overflow
i have a link that allows me to downlowd a text file in my web page but the problem is that i want the user to be able to chose where to save the file i mean when he clicks the link a window should be opened so he can save the file wherever he likes can any one tell me how to do that? thx . here is a part of my code: $fichierres=fopen('res.txt','a'); ftruncate($fichierres,0); ... fputs($fichierres, $t."\r\n"); ... fclose($fichierres); echo' <div style="text-align:center"><br> <button id="download" width="100px" class="styled-button-8"><a href="res.txt" download="res.txt" style="color: #FFFFFF"><b>Download</b></a></button></div><br>';
🌐
tanaike
tanaikech.github.io › home › "downloading files under specific folder using node.js"
Downloading Files Under Specific Folder using Node.js | tanaike - Google Apps Script, Gemini API, and Developer Tips
Change the SCOPE from var SCOPES ...eadonly'];. Run script, retrieve the code and authorize. function listFiles(auth) { var folderid = "### folder ID ###"; // Folder ID....
🌐
Reddit
reddit.com › r/javascript › specify file location for user-triggered download?
r/javascript on Reddit: Specify File Location for User-Triggered Download?
August 24, 2018 -

I'm using the code offered in [this S.O. post] (https://stackoverflow.com/questions/19721439/download-json-object-as-a-file-from-browser) to allow the user to download state settings. (For reference, this is a music app, and they are downloading their "compositions.")

This function places the file into the "downloads" folder. Is it possible to allow the user to specify which folder to put the file? (Eg: for the reverse operation, <input type="file"/> will open a dialogue box whereby the user specifies the file to be read.)

🌐
Stack Overflow
stackoverflow.com › questions › 27214011 › changing-download-folder-for-a-specific-web-application
javascript - Changing download folder for a specific web application - Stack Overflow
I think the answer is going to be "not possible" but it doesn't hurt to ask. I've created a web application for a specific user that in part creates Word Doc documents on the server that they then download to their local machines.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Mozilla › Add-ons › WebExtensions › Working_with_files
Work with files - Mozilla - MDN Web Docs
July 17, 2025 - The key method is downloads.download(), which in its simplest form accepts a URL and downloads the file from that URL to the user's default downloads folder: js · browser.downloads.download({ url: "https://example.org/image.png" }); You can let the user download to a location of their choice by specifying the saveAs parameter...