Skip to content

Instantly share code, notes, and snippets.

@navyjeff
Created August 1, 2013 17:09
Show Gist options
  • Save navyjeff/6133313 to your computer and use it in GitHub Desktop.
Save navyjeff/6133313 to your computer and use it in GitHub Desktop.
I used this to move all my video files from one directory into their own subdirectories with the same name as the file.
import os
import shutil
import fnmatch
path = os.getcwd()
filelist = os.listdir(path)
files = fnmatch.filter(filelist, '*.avi')
# If you have more than one file type:
# files += fnmatch.filter(filelist, '*.m4v')
# files += fnmatch.filter(filelist, '*.mkv')
for name in filelist:
os.mkdir(name[:-4])
shutil.move(name,name[:-4])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment