I have a directory with a few thousand files. I’d like to be able to make sub directories inside the larger director and move exactly 150 files (filtered by extension) into each of the newly created directories. I would love some guidance to get me going. Here is the trifle I’m starting with:
wd = os.chdir(r'foobar')
allgzs=[]
for file in os.listdir(wd):
if file.endswith('asc.gz'):
allgzs.append(file)
for gz in allgzs:
# For every 150 .gz files:
# Create directory -- os.mkdir?
# Move files into directory -- shutil.move?
I came up with a
grouperfunction to yield a long sequence in runs ofn:From there, you can do what you want pretty concisely: