Skip to content

Instantly share code, notes, and snippets.

@driscollis
Last active July 10, 2018 16:21
Show Gist options
  • Save driscollis/0bee792e7a35bb3fbfd4e51e0e290d1b to your computer and use it in GitHub Desktop.
Save driscollis/0bee792e7a35bb3fbfd4e51e0e290d1b to your computer and use it in GitHub Desktop.
import os
import shutil
def move_file_type_v2(path, ftype, excludes):
matches = glob.glob('{}/**/*{}'.format(path, ftype), recursive=True)
for match in matches:
dirname, filename = os.path.dirname(match), os.path.basename(match)
if dirname not in excludes:
proj_dir = os.path.join(dirname, 'ProjectData')
if os.path.exists(proj_dir):
shutil.move(match, os.path.join(proj_dir, filename))
if __name__ == '__main__':
path = '/home/mdriscoll/py/test/'
file_type = 'bmp'
excludes = [r'C:\Project\RandomFolder\Folder123']
move_file_type_v2(path, file_type, excludes=excludes)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment