Crates.io | refine |
lib.rs | refine |
version | 1.2.1 |
source | src |
created_at | 2022-06-02 02:12:57.870888 |
updated_at | 2024-11-19 04:42:13.652516 |
description | Refine your file collection using Rust! |
homepage | |
repository | https://github.com/rsalmei/refine |
max_upload_size | |
id | 598615 |
size | 92,634 |
This tool will help you manage and organize your collections of files like no other! It will help you find duplicated files, rename filenames and directories with advanced regex rules, strip and replace parts of their names, join them together in a single directory, filter and extract copies of files and directories, apply sequence numbers to equivalent names, and even group and completely rebuild their names to organize them however you want, and make everything refined and easier to find.
I've made this tool to be the fastest and easiest way to organize file collections. I use it a lot, and I hope it can help you too. It will scan several given paths at once and analyze all files and directories as a whole, performing some advanced operations on them. Enjoy!
It is blazingly fast, of course, like all Rust 🦀 software!
The name comes from "refine your [photos | images | videos | movies | porn | music | etc.] collection"!
Install refine
with:
cargo install refine
And that's it, you're ready to go! You can now call it anywhere.
Here is a much improved partial mode in Rebuild command, which can alter groups of filenames while preserving sequences, and even detect and fix gaps in sequences caused by deleted files.
Revamped join command! It now supports non-empty target folders, and will resolve clashes accordingly.
Also, several enum CLI arguments now support aliases, and I've fixed join command still moving files even when copy was requested.
Yes, it is time.
After a complete overhaul of the code, it's time to release 1.0!
It's an accomplishment I'm proud of, which took over 70 commits and a month's work, resulting in most of the code being rewritten.
It is more mature, stable, and well-structured now.
The major motivation for this version is the rebuild Partial mode! We can now rebuild collections even when some paths are not available! This means that files not affected by the specified naming rules will stay the same, keeping their sequence numbers, while new files are appended after the highest sequence found. It is handy for collections on external drives or cloud storage which are not always connected, allowing you to, even on the go, rebuild new files without messing up previous ones.
And this also includes:
--replace
option to replace all occurrences of some string or regex in the filenames with another one.-i
or on already organized collectionsjoin
command, already with directory support-i
and -x
options that filter both files and directories--clashes
option to allow them.
and _
, in addition to -
and spaces--dir-in
and --dir-out
options.rename
command--exclude
option to exclude filesdupes
and list
command will show partial resultsrebuild
command will just exit, as it needs all the files to run--include
option to filter input files--force
option to easily rename new files--dry_run
obsolete (removed), with new --yes
option to bypass it (good for automation)All commands will:
--include
and --exclude
)--dir-in
and --dir-ex
)Refine your file collection using Rust!
Usage: refine [OPTIONS] [PATHS]... <COMMAND>
Commands:
dupes Find possibly duplicated files by both size and filename
join Join all files into the same directory
list List files from the given paths
rebuild Rebuild the filenames of media collections intelligently
rename Rename files in batch, according to the given rules
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
Global:
-i, --include <REGEX> Include only these files and directories; checked without extension
-x, --exclude <REGEX> Exclude these files and directories; checked without extension
-I, --dir-in <REGEX> Include only these directories
-X, --dir-ex <REGEX> Exclude these directories
--file-in <REGEX> Include only these files; checked without extension
--file-ex <REGEX> Exclude these files; checked without extension
--ext-in <REGEX> Include only these extensions
--ext-ex <REGEX> Exclude these extensions
-w, --shallow Do not recurse into subdirectories
[PATHS]... Paths to scan
For more information, see https://github.com/rsalmei/refine
dupes
commandThe dupes
command will analyze and report the possibly duplicated files, either by size or name. It will even load a sample from each file, to guarantee they are indeed duplicated. It is a small sample by default but can help reduce false positives a lot, and you can increase it if you want.
Find possibly duplicated files by both size and filename
Usage: refine dupes [OPTIONS] [PATHS]...
Options:
-s, --sample <BYTES> Sample size in bytes (0 to disable) [default: 2048]
-h, --help Print help
Example:
❯ refine dupes ~/Downloads /Volumes/External --sample 20480
join
commandThe join
command will let you join all the files and directories in the given paths into the same directory. You can filter files however you like, and choose how they will be joined, either moving or copying them. It will even remove the empty parent directories after joining!
Note: any deletions are only performed after files and directories have been successfully moved/copied. So, in case any errors occur, the files and directories partially moved/copied will be found in the target directory, so you should manually delete them before trying again.
Join all files into the same directory
Usage: refine join [OPTIONS] [PATHS]...
Options:
-t, --to <PATH> The target directory; will be created if it doesn't exist [default: .]
-s, --strategy <STRATEGY> The strategy to use to join [default: move] [possible values: move, copy]
-c, --clash <CLASH> Specify how to resolve clashes [default: sequence] [possible values: sequence, parent, skip]
-f, --force Force joining already in place files and directories, i.e., in subdirectories of the target
-n, --no-remove Do not remove the empty parent directories after joining
-y, --yes Skip the confirmation prompt, useful for automation
-h, --help Print help
Example:
❯ refine join ~/media/ /Volumes/External/ -i 'proj-01' -X 'ongoing' -t /Volumes/External/proj-01
list
commandThe list
command will gather all the files in the given paths, sort them by name, size, or path, and display them in a friendly format.
List files from the given paths
Usage: refine list [OPTIONS] [PATHS]...
Options:
-b, --by <BY> Sort by [default: name] [possible values: name, size, path]
-d, --desc Use descending order
-h, --help Print help
Example:
❯ refine list ~/Downloads /Volumes/External --by size --desc
rebuild
commandThe rebuild
command is a great achievement, if I say so myself. It will smartly rebuild the filenames of an entire collection when it is composed by user ids or streamer names, for instance. It will do so by removing sequence numbers, stripping parts of filenames you don't want, smartly detecting misspelled names by comparing with adjacent files, sorting the detected groups deterministically by creation date, regenerating the sequence numbers, and finally renaming all the files accordingly. It's awesome to quickly find your video or music library neatly sorted automatically... And the next time you run it, it will detect new files added since the last time, and include them in the correct group! Pretty cool, huh? And don't worry, you can review all the changes before applying them.
Rebuild the filenames of media collections intelligently
Usage: refine rebuild [OPTIONS] [PATHS]...
Options:
-b, --strip-before <STR|REGEX> Strip from the start of the filename; blanks nearby are automatically removed
-a, --strip-after <STR|REGEX> Strip to the end of the filename; blanks nearby are automatically removed
-e, --strip-exact <STR|REGEX> Strip all occurrences in the filename; blanks nearby are automatically removed
-r, --replace <STR|REGEX=STR|$N> Replace all occurrences in the filename with another; blanks are not touched
-s, --no-smart-detect Disable smart detection of similar filenames (e.g. "foo bar.mp4", "FooBar.mp4" and "foo__bar.mp4")
-f, --force <STR> Force to overwrite filenames (use the Global options to filter files)
-p, --partial Assume not all paths are available, so only touch files actually modified by the given rules
-y, --yes Skip the confirmation prompt, useful for automation
-h, --help Print help
Example:
❯ refine rebuild ~/media /Volumes/External -a 720p -a Bluray -b xpto -e old
rename
commandThe rename
command will let you batch rename files like no other tool, seriously! You can quickly strip common prefixes, suffixes, and exact parts of the filenames, as well as apply any regex replacements you want. By default, in case a filename ends up clashing with other files in the same directory, that whole directory will be disallowed to make any changes. The list of clashes will be nicely formatted and printed, so you can manually check them. And you can optionally allow changes to other files in the same directory, removing only the clashes if you find it safe.
Rename files in batch, according to the given rules
Usage: refine rename [OPTIONS] [PATHS]...
Options:
-b, --strip-before <STR|REGEX> Strip from the start of the filename; blanks nearby are automatically removed
-a, --strip-after <STR|REGEX> Strip to the end of the filename; blanks nearby are automatically removed
-e, --strip-exact <STR|REGEX> Strip all occurrences in the filename; blanks nearby are automatically removed
-r, --replace <STR|REGEX=STR|$N> Replace all occurrences in the filename with another; blanks are not touched
-c, --clashes Allow changes in directories where clashes are detected
-y, --yes Skip the confirmation prompt, useful for automation
-h, --help Print help
Example:
❯ refine rename ~/media /Volumes/External -b "^\d+_" -r '([^\.]*?)\.=$1 '
--shallow
option.join
command, new magic filter options, new filter options; rename: include full directory support.--clashes
option to allow them..
and _
, --include
and --exclude
options do not check file extensions; dupes: remove case sensitivity option.--dir-in
and --dir-out
options.rename
command; rebuild, rename: improve strip exact.--exclude
.list
command.--include
is now case-insensitive; rebuild: fix smart detect not grouping some files, strip rules remove hyphens too.--include
; rebuild: new --force
, new interactive mode, new --yes
, auto fix rename errors, smaller memory consumption; dupes: improved performance.rebuild
command, general polishing overall.dupes
command, support match case and changing sample size.refine
, use split crate human-repr
.This software is licensed under the MIT License. See the LICENSE file in the top distribution directory for the full license text.
Maintaining an open source project is hard and time-consuming, and I've put much ❤️ and effort into this.
If you've appreciated my work, you can back me up with a donation! Thank you. 😊