Folder Structure CLI is a command-line tool written in Go that creates a folder structure based on a JSON file input. This tool is useful for quickly setting up project structures, organizing files, or replicating directory layouts.
- Create folders and files based on a JSON structure
- Simple command-line interface
- Recursive creation of nested structures
- Optional protection against overwriting existing files and folders
- Error handling and reporting
- Go 1.23.1 or later
- Clone the repository:
git clone https://github.com/ondrovicfolder-structure-cli.git
- Navigate to the project directory:
cd folder-structure-cli - Build the application:
go build
./folder-structure-cli create [json_file_path] [output_path] [flags][json_file_path]: Path to the JSON file describing the folder structure[output_path]: Path where the folder structure will be created
--no-overwriteor-n: Do not overwrite existing files and folders. When this flag is used, any existing files or folders will be skipped instead of being overwritten.
./folder-structure-cli create structure.json ./output./folder-structure-cli create structure.json ./output --no-overwriteor using the short flag:
./folder-structure-cli create structure.json ./output -nWhen using the --no-overwrite flag:
- Existing files and folders will be skipped
- A message will be displayed for each skipped item
- New files and folders will still be created normally
- This helps prevent accidental data loss
To display the version of the CLI:
./folder-structure-cli -vor
./folder-structure-cli --versionThe JSON file should describe the folder structure. Use null for files and nested objects for folders.
Example structure.json:
{
"folder1": {
"subfolder1": {
"file1.txt": null,
"file2.txt": null
},
"subfolder2": {}
},
"folder2": {
"file3.txt": null
},
"file4.txt": null
}This will create:
output/
├── folder1/
│ ├── subfolder1/
│ │ ├── file1.txt
│ │ └── file2.txt
│ └── subfolder2/
├── folder2/
│ └── file3.txt
└── file4.txt
When using the --no-overwrite flag, the tool will:
- Check if each file or folder already exists before creating it
- Skip creation if the item already exists
- Display a message indicating which items were skipped
- Continue processing the rest of the structure
This is particularly useful when:
- Adding new files to an existing project structure
- Running the command multiple times
- Protecting important existing files from being accidentally overwritten
The CLI will print error messages for:
- Invalid JSON files
- File read/write errors
- Invalid folder structures
- Permission issues
folder-structure-cli/
├── cmd/
│ ├── root.go
│ ├── create.go
│ ├── create_test.go
│ └── version.go
├── main.go
└── go.mod
main.go: Entry point of the applicationcmd/root.go: Defines the root command and version flagcmd/create.go: Implements thecreatecommand with no-overwrite functionalitycmd/create_test.go: Tests for the create command including no-overwrite scenarioscmd/version.go: Version command implementation
To add a new command:
- Create a new file in the
cmd/directory (e.g.,cmd/newcommand.go) - Define the command structure and functionality
- Add the command to the root command in the
init()function
go test ./...or with coverage:
make testContributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.