From ed73a9c7f3fb46f295bb81f05feaa74f9d4649b1 Mon Sep 17 00:00:00 2001 From: q Date: Thu, 25 Jun 2015 21:10:47 +0300 Subject: [PATCH] random split --- FolderSplit.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/FolderSplit.py b/FolderSplit.py index 1e314df..09b4f42 100755 --- a/FolderSplit.py +++ b/FolderSplit.py @@ -2,6 +2,7 @@ import os,sys import math,shutil,re +from random import shuffle VERSION="0.1" @@ -12,7 +13,8 @@ def setup_options(): parser=ArgumentParser(description="Splits files to subfolders equally.") parser.add_argument("--order",'-o',type=str,action='store', dest='order',default="sequence", - help="Splitting method: sequence, sparse, regexp") + help="Splitting method.", + choices=['sequence','sparse','regexp','random']) parser.add_argument("-m",action='store_true', dest='move',default=False, help="Move entries instead of hardlink.") parser.add_argument("-f",action='store_true', dest='files',default=False, @@ -133,9 +135,6 @@ def report(outFolders): options=setup_options() outFolders=[] method = options.order.lower().strip() -if method not in ('sparse','sequence','regexp'): - print("Writing order: \""+method+"\" not recognized.") - sys.exit(1) # list files, and remove hidden (.files) inFiles=sorted(filter(lambda x: not x.startswith('.'), os.listdir(options.path))) if options.files: @@ -151,7 +150,9 @@ else: for x in outFolders: if not os.path.isdir(x): os.mkdir(x) - +if method=='random': + shuffle(inFiles) + fileorder(inFiles,options.path,outFolders,options.n,options.move) if method=='regexp': regexorder(inFiles,options.path,outFolders,matcher,uniqlabel,options.move) if method=='sparse': @@ -159,4 +160,5 @@ if method=='sparse': if method=='sequence': fileorder(inFiles,options.path,outFolders,options.n,options.move) + report(outFolders)