https://github.com/goggle/flatten
Command-line tool to flatten a directory structure.
https://github.com/goggle/flatten
cleaner command-line-tool golang
Last synced: 9 months ago
JSON representation
Command-line tool to flatten a directory structure.
- Host: GitHub
- URL: https://github.com/goggle/flatten
- Owner: goggle
- License: mit
- Created: 2017-03-18T12:04:57.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-10-07T20:43:24.000Z (over 8 years ago)
- Last Synced: 2025-05-05T19:47:43.231Z (about 1 year ago)
- Topics: cleaner, command-line-tool, golang
- Language: Go
- Size: 31.3 KB
- Stars: 8
- Watchers: 3
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# flatten
Flatten is a command-line tool to flatten a directory structure.
+ [Installation](#installation)
+ [Usage](#usage)
+ [Example](#example)
## Installation
Make sure that you have [Go installed](https://golang.org/dl/), and that you have set up your [Go environment](https://golang.org/doc/code.html#GOPATH).
```
go get github.com/goggle/flatten
```
## Usage
```
Usage:
flatten [SOURCE] [DESTINATION] [-c | --copy-only] [-f | --force] [--include-source-files] [-s | --simulate-only] [--verbose]
flatten -h | --help
flatten -v
Recursively flatten the directory structure from SOURCE to DESTINATION.
Arguments:
SOURCE Optional source directory (default is current directory).
DESTINATION Optional destination directory (default is current directory).
Options:
-c --copy-only Do not remove anything from the source directory.
-f --force Do not propose a simulation first, immediately execute the command.
--include-source-files Include the files which are directly located in the SOURCE directory.
-s --simulate-only Do not move or copy any files on the system,
just output the expected result.
--verbose Explain what is being done.
-v --version Show version.
-h --help Show this screen.
```
## Example
Assume we have the following directory strcuture in `/home/goggle/example/`:
```
/home/goggle/example
├── c_progs
│ └── prog01
│ ├── hello
│ └── hello.c
├── data
│ ├── dat001
│ │ ├── data_apples.txt
│ │ ├── data_monkeys.txt
│ │ └── data_trees.txt
│ ├── dat002
│ │ ├── data_apples.txt
│ │ ├── data_monkeys.txt
│ │ └── data_trees.txt
│ ├── dat003
│ │ ├── data_apples.txt
│ │ ├── data_monkeys.txt
│ │ └── data_trees.txt
│ └── dat004
│ ├── data_apples.txt
│ ├── data_monkeys.txt
│ └── data_trees.txt
├── hello
└── hello_1
```
By running `flatten` in `/home/goggle/example` we get the following result:
```
/home/goggle/example
├── data_apples_1.txt
├── data_apples_2.txt
├── data_apples_3.txt
├── data_apples_4.txt
├── data_monkeys_1.txt
├── data_monkeys_2.txt
├── data_monkeys_3.txt
├── data_monkeys_4.txt
├── data_trees_1.txt
├── data_trees_2.txt
├── data_trees_3.txt
├── data_trees_4.txt
├── hello
├── hello_01
├── hello_1
└── hello.c
```
All the files in the subdirectories of `/home/goggle/example/` have been moved into `/home/goggle/example` and the empty directories have been removed. Note, that no regular file has been removed, even though we have file name collisions (e.g. the file `data_apples.txt` exists four times). Flatten does automatically take care of such filename collisions and adds a number to the filename if such a collision happens.
If we want to keep the original files in their subdirectories, we can use the `--copy-only` option. `flatten -c` or `flatten --copy-only` executed in `/home/goggle/example` will lead to the following result:
```
/home/goggle/example
├── c_progs
│ └── prog01
│ ├── hello
│ └── hello.c
├── data
│ ├── dat001
│ │ ├── data_apples.txt
│ │ ├── data_monkeys.txt
│ │ └── data_trees.txt
│ ├── dat002
│ │ ├── data_apples.txt
│ │ ├── data_monkeys.txt
│ │ └── data_trees.txt
│ ├── dat003
│ │ ├── data_apples.txt
│ │ ├── data_monkeys.txt
│ │ └── data_trees.txt
│ └── dat004
│ ├── data_apples.txt
│ ├── data_monkeys.txt
│ └── data_trees.txt
├── data_apples_1.txt
├── data_apples_2.txt
├── data_apples_3.txt
├── data_apples_4.txt
├── data_monkeys_1.txt
├── data_monkeys_2.txt
├── data_monkeys_3.txt
├── data_monkeys_4.txt
├── data_trees_1.txt
├── data_trees_2.txt
├── data_trees_3.txt
├── data_trees_4.txt
├── hello
├── hello_01
├── hello_1
└── hello.c
```
By default, flatten will perform a simulation of its actions first, and ask the user, if they want to continue.