搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

How do you format the download destination path?

more options

Say, for example, I want the download path to be "MyDownloadDirectory/%yyyy/%yyyy.%mm" which means "Change the download path every month to a folder named after the current year and the current month inside a folder named after the current year".

Many non-browser applications allow me to do this, but for some reason browsers generally don't have that option. I was thinking that there was a way to do this in Firefox.

What is a way to do this? If it's not possible in vanilla Firefox, is there an extension available for this?

Say, for example, I want the download path to be "MyDownloadDirectory/%yyyy/%yyyy.%mm" which means "Change the download path every month to a folder named after the current year and the current month inside a folder named after the current year". Many non-browser applications allow me to do this, but for some reason browsers generally don't have that option. I was thinking that there was a way to do this in Firefox. What is a way to do this? If it's not possible in vanilla Firefox, is there an extension available for this?

所有回复 (2)

more options

There are several prefs related to downloads.

This should be possible via the autoconfig.cfg file in the Firefox installation folder as you can run privileged JavaScript code via this file. See also:

You can give this a try as Firefox might be stubborn and wants to use the default download location.

To use Autoconfig, place two files into the Firefox installation directory.

  • on Windows, they go into the same directory where Firefox is installed
  • on macOS, they go into the Contents/Resources directory of the Firefox.app

The autoconfig.js file that specifies to use autoconfig.cfg is placed into the "defaults\pref" directory where the channel-prefs.js file is located.

//
pref("general.config.filename", "autoconfig.cfg");
pref("general.config.obscure_value", 0);
pref("general.config.sandbox_enabled", false); // disable sandbox

The autoconfig.cfg file is placed at the top level of the Firefox directory.

  • autoconfig.cfg and autoconfig.js need to start with a comment line (//)
  • autoconfig.js needs to use Unix line endings (LF instead of CR/LF)

Content of autoconfig.cfg in the Firefox installation folder.

//  autoconfig.cfg needs to start with a comment line
try{
let Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
let month = ((new Date).getMonth()+1).toString().replace(/^(\d{1})$/, "0$1");
let year = (new Date).getFullYear();
let path = Services.dirsvc.get("DfltDwnld", Ci.nsIFile).path; // you can replace this with another path
path += "/"+year+"/"+year+"."+month; // /%yyyy/%yyyy.%mm

Services.prefs.setCharPref("browser.download.dir", path);
Services.prefs.setCharPref("browser.download.lastDir", path);
Services.prefs.setIntPref("browser.download.folderList", 2);
} catch(e){Components.utils.reportError(e);}

Note that any error in autoconfig.cfg throws an error and abort processing this file.

由cor-el于修改

more options

Since you only need to change it monthly, perhaps it's simplest to set it up manually on the Settings page every month. If you need to include other factors such as the source site, or prefix/suffix the file name, an add-on probably is most logical. Note that for security reasons, add-ons are restricted to paths under your Downloads folder (or is it the system Downloads folder? I can't remember.).