Created
August 25, 2020 16:49
-
-
Save Disasm/09b263377ac6438e54a6520c5c149182 to your computer and use it in GitHub Desktop.
rust-cleaner
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
use std::process::Command; | |
use std::path::Path; | |
fn main() { | |
println!("Scanning file system..."); | |
let output = Command::new("locate").arg("Cargo.toml").output().expect("Failed to create process").stdout; | |
for line in output.split(|b| *b == 0x0a) { | |
if let Ok(s) = std::str::from_utf8(line) { | |
if s.is_empty() { | |
continue; | |
} | |
let path = Path::new(s); | |
if !path.is_file() { | |
continue; | |
} | |
let dir = path.parent().expect("Can't get parent directory"); | |
let target_dir = dir.join("target"); | |
if !target_dir.is_dir() { | |
continue; | |
} | |
println!("{}", target_dir.to_string_lossy()); | |
let status = Command::new("rm").arg("-rf").arg(&target_dir).status().expect("Failed to create process"); | |
if !status.success() { | |
println!("Error removing directory: rm exited with {}", status); | |
} | |
} else { | |
println!("Can't parse {:?}", line); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment