Skip to content

Instantly share code, notes, and snippets.

@binh-bk
Last active February 16, 2020 13:56
Show Gist options
  • Save binh-bk/a149d4199c8258f305a6d3377ee398cc to your computer and use it in GitHub Desktop.
Save binh-bk/a149d4199c8258f305a6d3377ee398cc to your computer and use it in GitHub Desktop.
find all video files by extensions and collect the files into one folder
# Binh Nguyen, Feb 15, 2020
'''
Moving files with movies or images to a designated folder
Useful to collect large files (movies) to one places
'''
import fnmatch
import os
import shutil
movies = ['*.mov', '*.avi', '*.AVI', '*.MOV', '*.mp4', '*.MP4']
rootFolder = '/path/to/root/folder'
targetFolder = '/path/to/collection/folder'
matches = []
print('Starting...')
for root, dirnames, filenames in os.walk(rootFolder):
for extensions in movies:
for filename in fnmatch.filter(filenames, extensions):
_path = os.path.join(root, filename)
matches.append(_path)
_new_path = os.path.join(targetFolder, filename)
shutil.move(_path, _new_path)
print('Moving {} to {}'.format(filename, _new_path))
# print(matches)
print('Done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment