Skip to content

Instantly share code, notes, and snippets.

@Disasm
Created August 25, 2020 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Disasm/09b263377ac6438e54a6520c5c149182 to your computer and use it in GitHub Desktop.
Save Disasm/09b263377ac6438e54a6520c5c149182 to your computer and use it in GitHub Desktop.
rust-cleaner
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