Created
February 1, 2014 02:10
-
-
Save Exodus111/8747003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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