Skip to content

Instantly share code, notes, and snippets.

Created July 15, 2013 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5998169 to your computer and use it in GitHub Desktop.
Save anonymous/5998169 to your computer and use it in GitHub Desktop.
#!/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