https://github.com/center-key/copy-folder-util
📂 Recursively copy a folder (CLI for package.json scripts)
https://github.com/center-key/copy-folder-util
cli command-line copy directory folder npm recursive script
Last synced: about 1 month ago
JSON representation
📂 Recursively copy a folder (CLI for package.json scripts)
- Host: GitHub
- URL: https://github.com/center-key/copy-folder-util
- Owner: center-key
- License: mit
- Created: 2022-09-19T23:23:48.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-20T07:13:47.000Z (9 months ago)
- Last Synced: 2025-05-07T22:06:36.257Z (9 months ago)
- Topics: cli, command-line, copy, directory, folder, npm, recursive, script
- Language: TypeScript
- Homepage:
- Size: 886 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# copy-folder-util

_Recursively copy files from one folder to another folder (CLI tool designed for use in npm package.json scripts)_
[](https://github.com/center-key/copy-folder-util/blob/main/LICENSE.txt)
[](https://www.npmjs.com/package/copy-folder-util)
[](https://github.com/center-key/copy-folder-util/actions/workflows/run-spec-on-push.yaml)
**copy-folder-util** takes a source folder and copies its files and subfolders to a new destination.
The command's console output includes a timestamp and formatting helpful in build systems.

## A) Setup
Install package for node:
```shell
$ npm install --save-dev copy-folder-util
```
## B) Usage
### 1. Synopsis
```
copy-folder [SOURCE] [TARGET]
```
Parameters:
* The **first** parameter is the *source* folder.
* The **second** parameter is the *target* folder.
### 2. npm package.json scripts
Run `copy-folder` from the `"scripts"` section of your **package.json** file.
Example **package.json** scripts:
```json
"scripts": {
"make-dist": "copy-folder build dist",
"make-docs": "copy-folder src/web --ext=.html docs/api-manual"
},
```
### 3. Command-line npx
Example terminal commands:
```shell
$ npm install --save-dev copy-folder-util
$ npx copy-folder src/web ext=.html docs/api-manual
```
You can also install **copy-folder-util** globally (`--global`) and then run it anywhere directly from the terminal.
### 4. CLI flags
Command-line flags:
| Flag | Description | Value |
| ------------ | ----------------------------------------------------- | ---------- |
| `--basename` | Filter files by filename ignoring the file extension. | **string** |
| `--cd` | Change working directory before starting copy. | **string** |
| `--ext` | Filter files by file extension, such as `.js`.
Use a comma to specify multiple extensions. | **string** |
| `--note` | Place to add a comment only for humans. | **string** |
| `--quiet` | Suppress informational messages. | N/A |
| `--summary` | Only print out the single line summary message. | N/A |
### 5. Examples
- `copy-folder build --basename=index dist`
Only copies files with filenames matching `index.*`.
- `copy-folder -cd=spec fixtures mock1`
Copies the folder **spec/fixtures** to **spec/mock1**.
- `copy-folder build dist --summary`
Displays the summary informaion but not informaion about individual files copied.
- `copy-folder 'src/Legal Notices' dist --summary`
Copies a folder that has a space in its name.
- `copy-folder src/web --ext=.js,.html docs`
Copies only the JavaScript and HTML files to the **docs** folder.
> [!NOTE]
> _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._
## C) Application Code
Even though **copy-folder-util** is primarily intended for build scripts, the package can be used programmatically in ESM and TypeScript projects.
Example:
``` typescript
import { copyFolder } from 'copy-folder-util';
const options = { fileExtensions: ['.html', '.js'] };
const results = copyFolder.cp('src/web', 'docs/api-manual', options);
console.info('Number of files copied:', results.count);
```
See the **TypeScript Declarations** at the top of [copy-folder.ts](src/copy-folder.ts) for documentation.
---
**CLI Build Tools for package.json**
- 🎋 [add-dist-header](https://github.com/center-key/add-dist-header): _Prepend a one-line banner comment (with license notice) to distribution files_
- 📄 [copy-file-util](https://github.com/center-key/copy-file-util): _Copy or rename a file with optional package version number_
- 📂 [copy-folder-util](https://github.com/center-key/copy-folder-util): _Recursively copy files from one folder to another folder_
- 🪺 [recursive-exec](https://github.com/center-key/recursive-exec): _Run a command on each file in a folder and its subfolders_
- 🔍 [replacer-util](https://github.com/center-key/replacer-util): _Find and replace strings or template outputs in text files_
- 🔢 [rev-web-assets](https://github.com/center-key/rev-web-assets): _Revision web asset filenames with cache busting content hash fingerprints_
- 🚆 [run-scripts-util](https://github.com/center-key/run-scripts-util): _Organize npm package.json scripts into groups of easy to manage commands_
- 🚦 [w3c-html-validator](https://github.com/center-key/w3c-html-validator): _Check the markup validity of HTML files using the W3C validator_
Feel free to submit questions at:
[github.com/center-key/copy-folder-util/issues](https://github.com/center-key/copy-folder-util/issues)
[MIT License](LICENSE.txt)