Moving Files By Type V1 (Python)

If you are like me then your computers file/folder structure goes a little “out of whack” over time. I’m looking to create a Python script that finds a particular file type and moves it into a folder. I’m running this on a MacBook (so Mac OS).

For my first version I just want to search in one folder for a particular file type and then move those files.

#Python to move particular file types

#Requires OS and shutil modules
import os
import shutil

print('GeekTechStuff presents the file type mover')

#Uses os to use user input to set the working directory
location = input('Folder that contains the files')
copy_location = ''
file_type = input('Which file type? e.g. jpeg')
file_type = '.'+file_type
print('You want to check: '+location+' for a file type of '+file_type)

#giving user the option to get out if needed
cont = input('Is this correct? Y or N: ')
cont = str.lower(cont)

if cont == 'n':
    print('Ending now, no further action')

elif cont == 'y':
    print('Continuing the program!')
    copy_location = input('Where should the files go?: ')
    for filename in os.listdir('.'):
        if filename.endswith(file_type):
            copy_location = copy_location+filename
            print('Moving ' + filename + ' to ' + copy_location)
            shutil.move(filename, copy_location)

    print('You were given two choices and managed to mess it up. This is why computers will one day rule the world!')

For the second version I will look to search a folder and its sub-directories.

My GitHub for this project is at

You may have noticed (from my screenshot) that I’m also testing a different Python IDE called PyCharm. I’m trying to see if a different IDE helps improve my productivity.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.