Secure file/folder structure generator with support for both tree diagrams and flat paths. Perfect for project scaffolding and boilerplate generation.
npm install file-tree-creatorA powerful CLI tool and library to generate file and folder structures from both tree diagrams and flat path lists. Perfect for quickly scaffolding projects or creating complex directory structures with a single command.
- Dual Input Modes: Supports both tree diagrams (ā āāā āāā) and flat path lists
- Smart Parsing: Handles comments (lines starting with #) and validates paths
- Safe Operations: Skips existing files and validates path characters
- Recursive Creation: Automatically creates all necessary parent directories
- CLI & Programmable: Use via command line or import as a library
bash
npm install -g file-tree-creator
`$3
`bash
npm install file-tree-creator --save-dev
`Usage š
$3
`bash
ftc [--mode=tree|flat]
`
or
`bash
npx file-tree-creator [--mode=tree|flat]
`#### Examples:
1. From a tree diagram:
`bash
ftc structure.txt
or explicitly
ftc structure.txt --mode=tree
`2. From flat paths:
`bash
ftc paths.txt --mode=flat
`$3
`javascript
const { parseTreeDiagram, parseFlatPath, createFileStructure } = require('file-tree-creator');// Using tree diagram
const treeInput =
;
const paths = parseTreeDiagram(treeInput);
createFileStructure(paths, './my-project');// Using flat paths
const flatInput =
;
const flatPaths = parseFlatPath(flatInput);
createFileStructure(flatPaths, './my-project');
`Input Formats š
$3
`
āāā src
ā āāā index.js
ā āāā utils
ā āāā helper.js
āāā README.md
āāā .gitignore
`$3
`
src/index.js
src/utils/helper.js
README.md
.gitignore
`$3
Both formats support comments (lines starting with #):
`
This is a comment
src/index.js # This part will be parsed
Another comment
`API Reference š
$3
Parses a tree diagram string into an array of paths.Parameters:
-
treeText (String): The tree diagram textReturns:
- Array of path strings
$3
Parses a flat path list into an array of paths.Parameters:
-
flatText (String): The flat path textReturns:
- Array of path strings
$3
Creates the file structure from an array of paths.Parameters:
-
paths (Array): Array of path strings
- baseDir (String): Base directory to create structure in (defaults to current directory)$3
By default, the tool runs in lenient mode:
- Continues after errors
- Shows warnings for invalid paths
- Returns exit code 0 unless catastrophic failure occurs
Use
--strict flag for strict mode:
- Fails immediately on first error
- Returns exit code 1 if any errors occur
- Recommended for CI/CD environmentsExamples:
`bash
Lenient mode (default)
ftc paths.txtStrict mode
ftc paths.txt --strict
`
Error Handling š
The tool handles several error cases gracefully:
- Skips existing files/folders with warning
- Rejects paths with invalid characters (
<>:"|?*)
- Rejects paths with double slashes (//)
- Provides clear error messages for file system operationsExamples šļø
See the
examples/ directory for sample input files:
- tree.txt: Tree diagram example
- flat.txt`: Flat path exampleContributions are welcome! Please open an issue or PR for any:
- Bug reports
- Feature requests
- Documentation improvements
- Test cases
MIT Ā© Festus Charles
---
Enjoy creating file structures with ease! šÆ