python - Shutil not copying all files -
i have folder files named this:
sheyenne_19840517.dat sheyenne_19840517.hdr sheyenne_19840704.dat sheyenne_19840704.hdr sheyenne_19840906.dat sheyenne_19840906.hdr sheyenne_19850520.dat sheyenne_19850520.hdr sheyenne_19850621.dat sheyenne_19850621.hdr sheyenne_19860726.dat sheyenne_19860726.hdr sheyenne_19860827.dat sheyenne_19860827.hdr sheyenne_19870830.dat sheyenne_19870830.hdr sheyenne_19870915.dat sheyenne_19870915.hdr
the numbers @ end of file names represent date. want seperate files month. files in may (or 05) own folder , on. trying use code right now:
import os import shutil hank_out=r'f:\sheyenne\roi\all_sheyenne_julian\by_month\ndvi' pth=r'f:\sheyenne\roi\all_sheyenne_julian\ndvi' f in os.listdir(pth): month=os.path.basename(f)[-8:-6] if not os.path.isdir(os.path.join(hank_out,month)): os.mkdir(os.path.join(hank_out, month)) shutil.copy(f, os.path.join(hank_out, month))
this copies first file encountered month. each folder has 1 file in output, , file first encountered month. not sure why of files not being copied.
Comments
Post a Comment