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.


#geektechstuff
#Python to move particular file types

#Requires OS and shutil modules
import os
import shutil

#title
print('')
print('GeekTechStuff presents the file type mover')
print('')
print('')

#Uses os to use user input to set the working directory
location = input('Folder that contains the files')
copy_location = ''
os.chdir(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!')
    print('')
    copy_location = input('Where should the files go?: ')
    print('')
    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)


else:
    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 https://github.com/geektechdude/file_mover

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.

Welcome to GeekTechStuff

my home away from home and where I will be sharing my adventures in the world of technology and all things geek.

The technology subjects have varied over the years from Python code to handle ciphers and Pig Latin, to IoT sensors in Azure and Python handling Bluetooth, to Ansible and Terraform and material around DevOps.

Let’s connect