file-organize
Version:
CLI tool for categorizing files
299 lines (225 loc) • 8.16 kB
Markdown
A powerful CLI tool for automatically categorizing and organizing files in directories based on their extensions.
[](https://opensource.org/licenses/MIT)
[](https://nodejs.org/)
- [Features](
- [Installation](
- [Binary Installation](
- [NPM Package Installation](
- [Build from Source](
- [Usage](
- [Options](
- [Examples](
- [Configuration](
- [Getting Started with Development](
- [Prerequisites](
- [Setup](
- [Running Tests](
- [Contributing](
- [Releasing](
- [License](
- 🗃️ Automatically categorize files based on their extensions into organized folders
- 🔄 Recursively process subdirectories
- 🚫 Exclude files or directories using regex patterns
- 📊 Dry run mode tree-based visualization to preview changes before applying them
- 🪄 Flat mode for organizing all files at the root level
- 🌲 Tree visualization of the post organized structure
- ⚙️ (In Progress) Customizable configuration through JSON files
There are several ways to install file-organize depending on your preference:
Download the pre-built binary for your operating system from the [Releases](https://github.com/himanshuc3/file-organize/releases) page.
- Download the `file-organize-win-x64.exe` file
- Rename it to `file-organize.exe` (optional)
- Add it to a location in your PATH or run it directly
```bash
curl -L -o file-organize "https://github.com/himanshuc3/file-organize/releases/latest/download/file-organize-macos-x64"
chmod +x file-organize
sudo mv file-organize /usr/local/bin/
```
```bash
curl -L -o file-organize "https://github.com/himanshuc3/file-organize/releases/latest/download/file-organize-linux-x64"
chmod +x file-organize
sudo mv file-organize /usr/local/bin/
```
Install globally to use as a command-line tool from anywhere:
```bash
npm install -g file-organize
yarn global add file-organize
pnpm add -g file-organize
```
If you want the latest features or need to customize the build:
```bash
git clone https://github.com/yourusername/file-organize.git
cd file-organize
npm install
npm run build
npm run pkg
```
```bash
file-organize [options]
```
| Option | Alias | Description | Type | Default |
| ------ | ------------- | ----------------------------------------------------------------------------------------------------------------- | ------- | ----------------------- |
| `-d` | `--directory` | Directory to organize | string | Current directory (`.`) |
| `-r` | `--recursive` | Recursively organize each subdirectory | boolean | `false` |
| `-e` | `--exclude` | Exclude files and directories using regex | string | none |
| `-c` | `--config` | Path to config file for mapping folders to extensions (not being consumed currently) | string | none |
| `-f` | `--flat` | Flat map all files to root directory (Use with recursive flag to convert a tree structure to flat directory tree) | boolean | `false` |
| `-o` | `--dryRun` | Output the final file tree before organizing (no changes made) | boolean | `false` |
| `-h` | `--help` | Show help | | |
### Examples
Basic usage to organize a directory:
```bash
# To organize current files in current directory without recursive iteration
file-organize
# To organize files in a specfic directory relative to the cwd
file-organize -d path/to/directory
```
Recursively organize a directory and all subdirectories:
```bash
file-organize -d path/to/directory -r
```
Perform a dry run to preview changes without making them:
```bash
file-organize -o
```
Exclude files or directories matching a pattern:
```bash
file-organize -e "node_modules|\.git"
```
## Default Configuration
The directories will categorize files according to the default configuration following the format given below. The option for customization will be supported soon via JSON files that can be saved and cached in system settings:
```json
{
"default": [
{
"name": "audio",
"extensions": ["mp3", "wav", "aac", "wma"]
},
{
"name": "video",
"extensions": ["mp4", "mov", "avi", "mkv", "flv", "wmv"]
},
{
"name": "documents",
"extensions": [
"zip",
"doc",
"docx",
"ppt",
"xls",
"html",
"txt",
"pdf"
]
},
{
"name": "executables",
"extensions": [
"exe",
"msi",
"dmg",
"pkg",
"deb",
"rpm",
"app",
"appx",
"appxbundle",
"appxupload"
]
},
{
"name": "images",
"extensions": [
"jpg",
"jpeg",
"png",
"svg",
"gif",
"ico",
"webp",
"heic",
"heif"
]
}
],
"prefix": "categorize",
"extra": {
"name": "miscellaneous"
}
}
```
- `prefix`: The prefix to be added to category folder names
- `default`: Array of category objects, each with a name and array of extensions
- `extra`: Configuration for uncategorized files
- Node.js 16.0.0 or higher
- npm, yarn, or pnpm (pnpm is recommended)
### Setup
1. Clone the repository:
```bash
git clone https://github.com/yourusername/file-organize.git
cd file-organize
```
2. Install dependencies:
```bash
npm install
```
3. Build the project:
```bash
npm run build
```
## Running Tests
To run the test suite:
```bash
npm run test
```
## Contributing
Contributions are welcome! There's a list of features/enhancements for the next version of the tool present in `Requirements.md` that are up for grabs. Please feel free to submit a Pull Request.
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
Please make sure your code follows the existing style and passes all tests.
## Releasing
To create a new release with automated binary builds:
1. Make sure all your changes are committed and merged to the main branch
2. Create and push a new tag with a version number:
```bash
git tag v1.0.0
git push origin v1.0.0
```
3. The GitHub Actions workflow will automatically:
- Build the project
- Create binaries for Windows, macOS, and Linux
- Publish a new GitHub Release with the binaries
- Publish the package to NPM
> Note: You need to have the NPM_TOKEN secret configured in your GitHub repository settings for the NPM publishing step to work.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.