0.1.0 • Published 8 months ago

special-folders v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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