Skip to content

Instantly share code, notes, and snippets.

@Exodus111
Created February 1, 2014 02:10
Show Gist options
  • Save Exodus111/8747003 to your computer and use it in GitHub Desktop.
Save Exodus111/8747003 to your computer and use it in GitHub Desktop.
"""
Folderizer 2
"""
import re
from path import path
root = path("./Test")
def find_pattern(names):
pattern = "S\d+E\d"
checked = {}
for i in names:
num = re.search(pattern, i.basename())
if num != None:
checked[i] = num.start()
return checked
def flatten(root):
folders = find_pattern(root.dirs())
for folder in folders:
for files in folder.walkfiles():
files = find_pattern([files])
for file in files:
path(file).move(root)
folder.rmtree_p()
def sort(root):
vidfiles = find_pattern(root.files())
for file in vidfiles:
filename = str(file.basename())
filename = filename[:vidfiles[file]].rstrip(".")
filename = filename.replace(".", " ")
folder = root / path(filename)
folder.mkdir_p()
file.move(folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment