#! /usr/bin/python3
# this script run on Linux, change path in accordance with your OS
import shutil
import fnmatch
import os
# images = ['*.jpg', '*.jpeg', '*.png', '*.tif', '*.tiff']
movies = ['*.mov', '*.mp4', '*.avi', '*.flv', '*.wmv','*.MOV', '*.MP4', '*.AVI', '*.FLV', '*.WMV']
#patterns = ['*_????_1.*'] # regex looking for my duplicated files
rootFolder = '/path/to/your/collection/folder'
mvFolder = '/path/to/your/designated/folder'
matches = []
print('Starting...')
_total_size = 0
for root, dirnames, filenames in os.walk(rootFolder):
for instance in movies: # change moviesto list of patterns or images
for filename in fnmatch.filter(filenames, instance):
# print("working on: {}".format(filenames)) # uncomment for monitoring
_path = os.path.join(root, filename)
_size = os.path.getsize(_path) # >> 20
_total_size += _size
matches.append(_path + '\t' + str(_size))
_new_path = os.path.join(mvFolder, filename)
shutil.move(_path, _new_path) # comment out for dry run
print('Moving {} to {}'.format(filename, _new_path))
# print(matches)
with open(os.path.join(mvFolder, 'log.txt'), 'w') as f: #change log file as desired
for item in matches:
f.write(item+'\n')
f.write("Total found size: {0:.2f} MB".format(_total_size/1024/1024))
print('Done.')