Created
August 9, 2015 13:49
-
-
Save nikos-glikis/16d4fead73b6e3a074c1 to your computer and use it in GitHub Desktop.
Recursive delete directory contents with python
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
def delete_directory_contents(folder): | |
for the_file in os.listdir(folder): | |
file_path = os.path.join(folder, the_file) | |
try: | |
if os.path.isfile(file_path): | |
os.unlink(file_path) | |
elif os.path.isdir(file_path): shutil.rmtree(file_path) | |
except Exception, e: | |
print e |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment