Created
January 13, 2020 15:16
-
-
Save theeluwin/7bb9283a67ab91c8c0192dd37d1137f3 to your computer and use it in GitHub Desktop.
인생 백업할때 소스코드만 백업합시다.
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
# -*- coding: utf-8 -*- | |
import os | |
import shutil | |
TARGET_PATH = "" | |
bad_dirnames = ( | |
'venv', | |
'.venv', | |
'node_modules', | |
'Debug', | |
'ipch', | |
'bower_components', | |
) | |
bad_filenames = ( | |
'.DS_Store', | |
) | |
bad_tails = ( | |
'sdf', | |
'sln', | |
'suo', | |
) | |
bad_mids = ( | |
'.vcproj', | |
'.vcxproj', | |
) | |
def remove_file(filepath): | |
try: | |
os.remove(filepath) | |
print(f"rm {filepath}") | |
except PermissionError: | |
print(f"permission denied: {filepath}") | |
def entry(): | |
walks = os.walk(TARGET_PATH) | |
for current_path, dirnames, filenames in walks: | |
for filename in filenames: | |
filepath = os.path.join(current_path, filename) | |
if filename in bad_filenames: | |
remove_file(filepath) | |
elif filename.split('.')[-1] in bad_tails: | |
remove_file(filepath) | |
else: | |
for bad_mid in bad_mids: | |
if bad_mid in filename: | |
remove_file(filepath) | |
for dirname in dirnames: | |
if dirname in bad_dirnames: | |
dirpath = os.path.join(current_path, dirname) | |
try: | |
shutil.rmtree(dirpath) | |
print(f"rm -rf {dirpath}") | |
except PermissionError: | |
print(f"permission denied: {filepath}") | |
if __name__ == '__main__': | |
entry() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment