Created
March 6, 2019 10:53
-
-
Save jfrantz1-r7/10e5372aab910989f5b5c64245101dee 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
import os | |
import shutil | |
fullpath = os.path.join | |
python_directory = "./py" | |
start_directory = "./mixed" | |
text_files = "./txt" | |
default_path = "./default" | |
#This is the dictionary to look up file extensions | |
dir_lookup = { | |
'docx': './docx/', | |
'txt': './txt/' | |
} | |
def get_extension(filename): | |
return filename[filename.rfind('.')+1:] | |
def main(): | |
for dirname, dirnames, filenames in os.walk(start_directory): | |
for filename in filenames: | |
source = fullpath(dirname, filename) | |
extension = get_extension(filename) | |
if (extension in dir_lookup): | |
shutil.move(source, fullpath(dir_lookup[extension], filename)) | |
else: | |
shutil.move(source, fullpath(default_path, filename)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment