Skip to content

A NodeJS library that creates several utility functions over the native fs module for directories

License

Notifications You must be signed in to change notification settings

GeorgianStan/dir-fs-utils

Repository files navigation

Dir Utils

issues forks stars license version

dir-fs-utils is aiming to be a collection of the utility functions for directories build on top of the native fs module.

Installation

npm i dir-fs-utils

Then anywhere in your code.

import { DirUtils } from 'dir-fs-utils`

or

const { DirUtils } = require('dir-fs-utils');

How to use it

await DirUtils.getFolderSize(folder_path);

await DirUtils.listFolderContent(folder_path);

Methods (3)

(1)

async listFolderContent(path: string): Promise<string[]> {}

This method will return an array with all the files in a folder.

If the provided path does not exist or is not accessible, then it will generate an error.


(2)

async getFolderSize(path: string): Promise<number> {}

This method will return the total size of a folder in bytes.

If the provided path does not exist or is not accessible, then it will generate an error.


(3)

async unwrap(folderPath: string, options?: UnwrapOptions): Promise<Map<string, string>>
export interface UnwrapOptions {
  keepFolder?: boolean;
  force?: boolean;
}

This method will open the contents of a folder. By default, it will remove the original folder and undo only files for which the destination path does not exist.

The returned value is a map that will contain all the files that failed to be unwrapped. If the size of the map is 0, then all the files were unwrapped successfully.

  • keepFolder?:boolean - if this property is set to true, then the original folder will remain intact(files will not be deleted)
  • force?:boolean - if this property is set to true, then the destination of the unwrapped files will overwritten

Contributing

Pull requests and stars are always welcome. Please check the guidelines.

Stay in touch

Author - Stan Georgian

License

This project is licensed under the MIT License

About

A NodeJS library that creates several utility functions over the native fs module for directories

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published