renfls

package module
v0.0.0-...-bc10cbf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 30, 2021 License: MIT Imports: 7 Imported by: 0

README

renfls

renfls renames files that match patterns to the directory name of each file.
renfls doesn't delete the files, it just renames them.

Before
root/
├── dir1/
│   ├── text.txt
│   └── image.jpg
├── dir2/
│   ├── text.txt
│   ├── あいうえお.txt
│   └── data.dat
└── dir3/
    ├── dir3-1/
    │   ├── music.mp3
    │   └── tmp.csv
    └── dir3-2/
        └── text.txt
After
root/
├── dir1.txt
├── dir1.jpg
├── dir2.txt
├── dir2-2.txt
├── dir3.mp3
├── dir3.txt
└── ignore/
    ├── data.dat
    └── tmp.csv

Installation

$ go get github.com/shoarai/renfls

Usage

CLI
$ renfls -dest=dest root
go
package main

import "github.com/shoarai/renfls"

func main() {
    // Move files that match the condition in the "root" directory to the "dest" directory.
    condition := renfls.Condition{Exts: "jpg", Reg: "image*", Ignore: false}
    if e := renfls.WalkToRootSubDirName("root", "dest", condition); e != nil {
        // fmt.Println(e)
    }
}
Option
Option Description
-dest Destination to which renamed files are moved
-ext Rename files only matching extension list separated by ","
-ignore Exclude files matching patterns

For example, the following command renames files whose extension is not "jpg" or "mp4" in the "root" directory and moves them to the "dest" directory.

$ renfls -dest=dest -ext=jpg,mp4 -ignore root

Documentation

Overview

Package renfls provides interfaces to rename files in directory.

Package renfls provides interfaces to rename files in directory.

Package renfls provides interfaces to rename files in directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Rename

func Rename(oldPath, dest, newName string) (string, error)

Rename renames a file or a directory and moves it to a directory.

func RenameCondition

func RenameCondition(root, dest, newFileName string, needRename NeedRename) error

RenameCondition renames all files matching condition in root and moves these to a directory.

func RenameExt

func RenameExt(root, dest, newFileName string, exts []string) error

RenameExt renames all files matching extensions in root and moves these to a directory.

func RenameIgnoreExt

func RenameIgnoreExt(root, dest, newFileName string, exts []string) error

RenameIgnoreExt renames all files not matching extension ins root and moves these to a directory.

func RenamePattern

func RenamePattern(root, dest, newFileName, pattern string) error

RenamePattern renames all files matching pattern in root and moves these to a directory.

func ToDirName

func ToDirName(root, newDir string) error

ToDirName renames all files in root by the root directory name and moves these to a directory.

func ToDirNameExt

func ToDirNameExt(root, newDir string, exts []string) error

ToDirNameExt renames all files matching extensions in root by the root directory name and moves these to a directory.

func ToDirNameIgnoreExt

func ToDirNameIgnoreExt(root, newDir string, exts []string) error

ToDirNameIgnoreExt renames all files not matching extensions in root by the root directory name and moves these to a directory.

func ToDirNamePattern

func ToDirNamePattern(root, newDir, pattern string) error

ToDirNamePattern renames all files matching pattern in root by the root directory name and moves these to a directory.

func ToSubDirsName

func ToSubDirsName(root string) error

ToSubDirsName renames all files in root by the directories name in root and moves these to a directory.

func ToSubDirsNameExt

func ToSubDirsNameExt(root string, exts []string) error

ToSubDirsNameExt renames all files matching extensions in root by the directories name in root and moves these to a directory.

func ToSubDirsNameIgnoreExt

func ToSubDirsNameIgnoreExt(root string, exts []string) error

ToSubDirsNameIgnoreExt renames all files not matching extensions in root by the directories name in root and moves these to a directory.

func ToSubDirsNamePattern

func ToSubDirsNamePattern(root, pattern string) error

ToSubDirsNamePattern renames all files matching pattern in root by the directories name in root and moves these to a directory.

func WalkRename

func WalkRename(root, dest, newFileName string, condition Condition) error

WalkRename renames files that match a condition in a root directory and moves them to a destination directory.

func WalkRenameAll

func WalkRenameAll(root, dest, newFileName string) error

WalkRenameAll renames all files in a root directory and moves them to a destination directory.

func WalkToRootDirName

func WalkToRootDirName(root, dest string, condition Condition) error

WalkToRootDirName renames files that match a condition in a root directory to the root directory name and moves them to a destination directory.

func WalkToRootSubDirName

func WalkToRootSubDirName(root, dest string, condition Condition) error

WalkToRootSubDirName renames files that match a condition in a root directory to the sub directory name and moves them to a destination directory.

Types

type Condition

type Condition struct {
	Exts   []string
	Reg    string
	Ignore bool
}

Condition is condition to rename files.

type NeedRename

type NeedRename func(info os.FileInfo) bool

NeedRename returns whether the file needs to be rename.

Directories

Path Synopsis
cmd
renfls command
renfls renames all files or files matching patterns in directories.
renfls renames all files or files matching patterns in directories.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL