Created
July 15, 2013 07:50
-
-
Save anonymous/5998169 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
#!/usr/bin/python | |
import sys | |
import os | |
import shutil | |
# Change this number to adjust the definition of a "small" download | |
THRESHOLD = 5 | |
foldername = sys.argv[1] | |
# ----- move-delete if files in the folder lower than THRESHOLD ----- | |
main_directory_path, downloaded_directory_name = os.path.split(foldername) | |
downloaded_files = os.listdir(foldername) | |
if len(downloaded_files) < THRESHOLD: | |
for downloaded_file in downloaded_files: | |
shutil.move(os.path.join(foldername, downloaded_file), | |
main_directory_path) | |
print("File(s) moved ...") | |
if os.path.exists(foldername): | |
shutil.rmtree(foldername) | |
print("Directory removed ...") | |
else: | |
print("Nothing moved, too many files ...") | |
print("**Done**") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment