I have a program that I am trying to write that will take a very large directory (10,000+files inside) and will create new sub directories to break the very large directory into smaller chunks (of approximately 100 files each).The program that I have currently raises no errors when i call it in terminal, but it does not actually sort the large file... I think the problem is with os.rename() but I dont understand why i also tried shutil.move() and still had the same problem. Sorry I couldent make code appear in color I am new to the site
#!/usr/bin/python
import os
import glob
import sys
from functools import partial
sys.setrecursionlimit(1000)
def mk_osdict(a):
#os.chdir(a)
#grouping files with .mol2 endings only
os_list =glob.glob("*.mol2")
#making a dictionary for the list of files in the directory
os_dict = dict([i,n] for i,n in zip(range(len(os_list)),os_list))
return os_dict
dict_os = mk_osdict("decoys")
#function to sort files into new directories with a specific size.
def init_path(f):
block = (len(f)/100)+1
#i_lst gives a list of the number of entries
i_lst = [str(i) for i in range(block)]
'''paths keys will become new directories, values will be a list
files to be sorted into the corresponding directory'''
paths = dict(["decoydir"+n.zfill(5),[]] for n in i_lst)
for lst in paths.values():
while len(lst) <= block:
for value in f.values():
lst.append(value)
for x,p in paths:
if not os.path.exists(x):
os.mkdir(x)
else:
pass
for index in p:
yield os.rename(index,os.path.join(x,index))
b = init_path(dict_os )