Copies or moves every file in a directory recursively to a target directory

Usage no npm install needed!

<script type="module">
  import flattenDirectory from 'https://cdn.skypack.dev/flatten-directory';


Flatten Directory

Copies every file in a directory recursively to a target directory. Renames every file to start with a prefix of the directories walked to avoid naming collisions. Directories are relative to the cwd or current working directory.


npm i -g flatten-directory

Usage without args


Will use cwd as the root directory and will copy every file into a new directory flatten-directory-output

Usage with args. Every arg is optional.

flatten-directory --rootdir="downloads" --outputdir="downloadsflattened"

The rootdir will be interpreted as cwd/rootdir. In this case cwd/downloads The outputdir will be interpreted as cwd/outputdir. In this case, cwd/downloadsflattened cut will tell flatten-directory to cut/move the files rather than copying them


if rootdir contains the following structure:


The files in the outputdir will be the following: