Skip to content

Instantly share code, notes, and snippets.

@julcap
Last active May 4, 2016 13:04
Show Gist options
  • Save julcap/65be39a73858c25d9c2e8c5c30b91b3c to your computer and use it in GitHub Desktop.
Save julcap/65be39a73858c25d9c2e8c5c30b91b3c to your computer and use it in GitHub Desktop.
Log fragmenting tool
# Log fragmenting 'tool'
# Author: Julian Capilla-krumbak
# Date: 2016-05-04
#
# Expected log format: yyyymmdd_xxxxxxxxxxxx
# It will put logs in folders per day like ./20160101/ ./20160102/ .. etc
import os,shutil
class FolderDist(object):
def __init__(self):
files = input("Enter path to files[{}]: ".format(os.getcwd()))
if files:
path = files
else:
path = os.getcwd()
months = ['01','02','03','04','05','06','07','08','09','10','11','12']
for i in months:
wpath = os.path.join(path,i)
if os.path.exists(wpath):
for x in os.listdir(wpath):
file = os.path.join(wpath,x)
newDir = os.path.join(wpath, x.split('_')[0])
if not os.path.exists(newDir):
os.mkdir(newDir)
if file != newDir:
print("Moving {} -> {}".format(file,newDir))
shutil.move(file,newDir)
if __name__ == '__main__':
test = FolderDist()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment