Created
January 16, 2018 16:20
-
-
Save QaisarRajput/fb1b13d8f4b817a9a5f1afbb2f246006 to your computer and use it in GitHub Desktop.
Divide data in a folder into batches
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed May 31 12:08:35 2017 | |
@author: Qaisar.Tanvir | |
""" | |
import os | |
import sys | |
import shutil | |
main = r"folder" | |
count = len(os.listdir(main)) | |
batchsize = 6 | |
postfix = 0 | |
for i,f in enumerate(os.listdir(main)): | |
batchfolder = os.path.join(main,"batch "+ str(postfix)) | |
if not os.path.exists(batchfolder): | |
os.makedirs(batchfolder) | |
if(i % (count/batchsize) == 0): | |
postfix += 1 | |
if not os.path.exists(os.path.join(main,"batch "+ str(postfix))): | |
os.makedirs(os.path.join(main,"batch "+ str(postfix))) | |
batchfolder = os.path.join(main,"batch "+ str(postfix)) | |
shutil.copy2(os.path.join(main,f),batchfolder) | |
else: | |
shutil.copy2(os.path.join(main,f),batchfolder) | |
print i | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment