Crates.io | file-split-to-directory |
lib.rs | file-split-to-directory |
version | 1.0.1 |
source | src |
created_at | 2024-10-14 08:59:50.270037 |
updated_at | 2024-10-14 08:59:50.270037 |
description | split files to folders |
homepage | https://github.com/hoshiyuki-tamako/file-split-to-directory-rs |
repository | https://github.com/hoshiyuki-tamako/file-split-to-directory-rs |
max_upload_size | |
id | 1408103 |
size | 27,598 |
split files to folders
cargo install file-split-to-directory
file-split-to-directory .
file-split-to-directory "/mnt/d/download"
# each folder 4400 files (default is 4400)
file-split-to-directory "/mnt/d/download" --chunk 4400
file-split-to-directory "/mnt/d/download" -c 4400
from
- Download
-- 1.png
-- 2.png
-- 3.png
-- ....
-- 4401.png
-- ....
-- 8801.png
to
- Download
|- 0
||- 1.png
||- 2.png
||- 3.png
||- ...
|- 1
||- 4401.png
||- ...
|- 2
||- 8801.png
use anyhow::Result;
use file_split_to_directory::FileSplitToDirectoryBuilder;
use std::num::NonZeroUsize;
fn main() -> Result<()> {
FileSplitToDirectoryBuilder::default()
.with_path("/tmp/test".into())
.with_chunk(NonZeroUsize::new(100).unwrap())
.build()? // std::io::Error if path = None
.execute()?;
Ok(())
}
use anyhow::Result;
use file_split_to_directory::FileSplitToDirectoryBuilder;
fn main() -> Result<()> {
FileSplitToDirectoryBuilder::default()
.with_path("/tmp/test".into())
.with_directory_name(|i: usize| i.to_string())
.build()?
.execute()?;
Ok(())
}
use anyhow::Result;
use file_split_to_directory::FileSplitToDirectoryBuilder;
use std::fs::DirEntry;
fn main() -> Result<()> {
// default order
FileSplitToDirectoryBuilder::default()
.with_path("/tmp/test".into())
.with_sort_cmp(|a: &DirEntry, b: &DirEntry| {
natord::compare( // cargo install natord
&a.file_name().to_string_lossy(),
&b.file_name().to_string_lossy(),
)
})
.build()?
.execute()?;
// order file by size
FileSplitToDirectoryBuilder::default()
.with_path("/tmp/test".into())
.with_sort_cmp(|a: &DirEntry, b: &DirEntry| {
b.metadata()
.map(|m| m.len())
.unwrap_or_default()
.cmp(&a.metadata().map(|m| m.len()).unwrap_or_default())
})
.build()?
.execute()?;
Ok(())
}