Giter Site home page Giter Site logo

kwchang0831 / fog Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 1.0 46 KB

๐Ÿ—‚๏ธ File Organizer written in Go. Can do flatten out folders, rename based on patterns/regex, etc...

License: MIT License

Go 100.00%
golang file-organizer go prototype

fog's Introduction

๐Ÿ—‚๏ธ fog

Files Organizer in Go

A little tool to help organize files easier.

Note

This project is a small prototype from my early days of learning Golang, approximately 10 years ago.
While it may still be functional, it has undergone limited testing.
Caution is advised, particularly in production environments.
Every commit generates a log, enabling easy reversion if necessary.
However, please be mindful of potential risks before proceeding.

Installation

Install Go

Get Go from https://go.dev/doc/install

Or via package manager: chocolatey:

choco install go

Check go version

go version

Install/Update this tool

Install via go command:

go install github.com/kwchang0831/fog@latest

Usages

folderout

Move files in the folder in current directory out of their folders.

fog folderout "." -w

"." : Target directory. Defaults to "." if omitted.

-w : Commit changes. Without the flag wil be dry run.

BeforeAfter
.
โ”œโ”€โ”€ SomeVideo_S01E01
    โ”œโ”€โ”€ SomeVideo_S01E01.mp4
    โ”œโ”€โ”€ SomeVideo_S01E01.jpg 
โ”œโ”€โ”€ SomeVideo_S01E02
    โ”œโ”€โ”€ SomeVideo_S01E02.avi
            
.
โ”œโ”€โ”€ SomeVideo_S01E01.mp4
โ”œโ”€โ”€ SomeVideo_S01E01.jpg 
โ”œโ”€โ”€ SomeVideo_S01E02.avi
            

folderin

Move SomeVideo_SXXEXX into their individual folder.

fog folderin "." -w

"." : Target directory. Defaults to "." if omitted.

-w : Commit changes. Without the flag wil be dry run.

BeforeAfter
.
โ”œโ”€โ”€ SomeVideo_S01E01.mp4
โ”œโ”€โ”€ SomeVideo_S01E01.jpg
โ”œโ”€โ”€ SomeVideo_S01E02.avi
            
.
โ”œโ”€โ”€ SomeVideo_S01E01
    โ”œโ”€โ”€ SomeVideo_S01E01.mp4
    โ”œโ”€โ”€ SomeVideo_S01E01.jpg
โ”œโ”€โ”€ SomeVideo_S01E02
    โ”œโ”€โ”€ SomeVideo_S01E02.avi
            

revert

Undo committed actions from target log file.

fo revert -w [pathToTheLog]

-w : Commit changes. Without the flag wil be dry run.

replacename

Remove [Bad] in file name only

fog replacename "\[Bad\]" "" -d "." -w

-d: Set directory.

-w : Commit changes. Without the flag wil be dry run.

BeforeAfter
.
โ”œโ”€โ”€ [Bad]SomeVideo_Folder[Bad] 
โ”œโ”€โ”€ [Bad]SomeVideo_S01E01[Bad].mp4
โ”œโ”€โ”€ [Bad]SomeVideo_S01E02[Bad].avi
            
.
โ”œโ”€โ”€ [Bad]SomeVideo_Folder[Bad]  
โ”œโ”€โ”€ SomeVideo_S01E01.mp4
โ”œโ”€โ”€ SomeVideo_S01E02.avi
            

Replace [Bad] in folder name only

fog replacename "\[Bad\]" "" -d "." -m1 -w

-d: Set directory.

-w : Commit changes. Without the flag wil be dry run.

-m1: Mode 1: Folder name only.

BeforeAfter
.
โ”œโ”€โ”€ [Bad]SomeVideo_Folder[Bad]   
โ”œโ”€โ”€ [Bad]SomeVideo_S01E01[Bad].mp4
โ”œโ”€โ”€ [Bad]SomeVideo_S01E02[Bad].avi
            
.
โ”œโ”€โ”€ SomeVideo_Folder
โ”œโ”€โ”€ [Bad]SomeVideo_S01E01[Bad].mp4
โ”œโ”€โ”€ [Bad]SomeVideo_S01E02[Bad].avi
            

Remove [Bad] in both folder name and file name

fog replacename "\[Bad\]" "" -d "." -m2 -w

-d: Set directory.

-w : Commit changes. Without the flag wil be dry run.

-m2: Mode 2: Folder and File name.

BeforeAfter
.
โ”œโ”€โ”€ [Bad]SomeVideo_Folder[Bad]   
โ”œโ”€โ”€ [Bad]SomeVideo_S01E01[Bad].mp4
โ”œโ”€โ”€ [Bad]SomeVideo_S01E02[Bad].avi
            
.
โ”œโ”€โ”€ SomeVideo_Folder
โ”œโ”€โ”€ SomeVideo_S01E01.mp4
โ”œโ”€โ”€ SomeVideo_S01E02.avi
            

Replace filename with regex

fog replacename "(.*)(SomeVideo)(.*)(S[0-9]+E[0-9]+)(.*)(\.(mp4|avi))" "$2-$4$6" -d "." -w

-d: Set directory.

-w : Commit changes. Without the flag wil be dry run.

Learn more and try regex, see regex101.

BeforeAfter
.
โ”œโ”€โ”€ [20240202]SomeVideo_S01E01[Bad].mp4
โ”œโ”€โ”€ [20240207]SomeVideo_S01E02[Bad].avi
            
.
โ”œโ”€โ”€ SomeVideo-S01E01.mp4
โ”œโ”€โ”€ SomeVideo-S01E02.avi
            

Show Help

For more information, please check help command.

fog

Output

File Organizer in Go provides commands to help you batch edit filenames and organize files.

Usage:
  fog [command]

Available Commands:
  completion        Generate the autocompletion script for the specified shell
  folderin          move files into their own folders.
  folderout         Move files out of folders
  help              Help about any command
  move              Move matching files/folders into target directory.
  renameafterfolder Rename files inside matching folders with the folder name.
  replacename       Replace name using the search pattern and replace pattern.
  revert            revert commands issued.
  rmemptydir        remove empty folders.

Flags:
  -h, --help   help for fog

Use "fog [command] --help" for more information about a command.

Development

Upgrade dependencies

go get -u

Get dependencies

go mod tidy

Build

go build

fog's People

Contributors

kwchang0831 avatar

Watchers

 avatar  avatar

Forkers

ivandovgalyuk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.