Last active
December 22, 2017 14:13
-
-
Save juchiast/2112927eabbea6092fa564704d035dc3 to your computer and use it in GitHub Desktop.
Rename files with Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "jslife" | |
version = "0.1.0" | |
authors = ["Do Duy"] | |
[dependencies] | |
walkdir = "2.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate walkdir; | |
use walkdir::WalkDir; | |
fn rename() -> std::io::Result<()> { | |
for entry in WalkDir::new(".") { | |
let path = entry?.path().to_owned(); | |
let ex = path.extension(); | |
if path.is_file() && ex.is_some() && ex.unwrap() == "lif" { | |
let mut new_path = path.clone(); | |
new_path.set_extension("rle"); | |
std::fs::copy(&path, &new_path)?; | |
std::fs::remove_file(&path); | |
} | |
} | |
Ok(()) | |
} | |
fn main() { | |
rename(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment