special-folders
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

special-folders

To get folder paths of special folders like desktop, downloads, pictures, ...

Inspired by window.showDirectoryPicker, Environment.GetFolderPath and downloads-folder

Usage

import path from 'node:path';
import fs from 'node:fs';
import {getFolderPath, SpecialFolder, SpecialFolderOption} from 'special-folders';


let downloadsPath = getFolderPath(SpecialFolder.Downloads);
if(!downloadsPath){
  throw new Error('Cannot get downloads folder which exists');
}

// or

let downloadsPath = getFolderPath(SpecialFolder.Downloads, SpecialFolderOption.DoNotVerify);
if(!fs.existsSync(downloadsPath)) { // rare but still trying
  fs.mkdirSync(downloadsPath, {recursive: true});
}

Notes for Windows users:

When installing on Windows, the postinstall script of this package will install additional dependency registry-js, which is not listed in package.json.

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i special-folders

      Weekly Downloads

      1

      Version

      0.1.0

      License

      MIT

      Unpacked Size

      8.27 kB

      Total Files

      7

      Last publish

      Collaborators

      • fuweichin