https://github.com/wolfchamane/amjs-utils-fs
Provides set of top-level utilities for filesystem management
https://github.com/wolfchamane/amjs-utils-fs
Last synced: about 1 year ago
JSON representation
Provides set of top-level utilities for filesystem management
- Host: GitHub
- URL: https://github.com/wolfchamane/amjs-utils-fs
- Owner: Wolfchamane
- License: mit
- Created: 2019-07-25T12:58:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T02:03:13.000Z (over 3 years ago)
- Last Synced: 2025-02-25T14:46:12.310Z (over 1 year ago)
- Language: JavaScript
- Size: 770 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @amjs/utils-fs 0.1.4
   
> Provides set of top-level utilities for filesystem management
## Installation
```bash
$ npm i @amjs/utils-fs
```
## Usage
Given the following tre:
```
/
folder/
file.txt
index.html
```
#### make-folder
Creates a folder following a complete path address.
```javascript
const { makeFolder } = require('@amjs/utils-fs');
const path = require('path');
const root = path.join('/', 'folder', 'new-folder'); // '/folder/new-folder'
makeFolder(root);
```
Will output following tree:
```
/
folder/
new-folder/
file.txt
index.html
```
#### scan-dir
Scans a folder returning an array with all contained file paths.
```javascript
const { scanDir } = require('@amjs/utils-fs');
const path = require('path');
const root = path.join('/', 'folder');
let files = scanDir(root);
console.log(files); // [ '/folder/file.txt', '/folder/index.html' ]
// Use second argument to exclude files from output
files = scanDir(root, [ path.join(root, 'file.txt') ];
console.log(files); // [ '/folder/index.html' ]
// Use third argument to filter output by a regular expression
files = scanDir(root, [], /.+\.m?js$/);
console.log(files); // []
```