Skip to content

Instantly share code, notes, and snippets.

@antoinevg
Created July 25, 2022 21:23
Show Gist options
  • Save antoinevg/494ae08d82ed1f0c428e736c36149b47 to your computer and use it in GitHub Desktop.
Save antoinevg/494ae08d82ed1f0c428e736c36149b47 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import shutil
import subprocess
dir = '<your projects root>'
print('Cleaning rust projects in ' + dir + ' and all its subfolders.')
for dirpath, dirnames, filenames in os.walk(dir):
for directory in dirnames:
if directory.startswith('.'):
continue
# assume it's a rust project if directory has a target/ folder
if directory == 'target':
print('Running `cargo clean` in: ' + dirpath)
command = ['cargo', 'clean']
with subprocess.Popen(command, cwd=dirpath, stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
print(line, end='')
print('Task completed!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment