# -*- coding: utf-8 -*-
"""
Created on Fri Mar 11 12:14:57 2022

@author: igskmncn-phoenix
"""


import os, sys, glob, shutil
count = 0

workingDir = r'S:\images\Paul Young finished'
#os.chdir(workingDir)

for file in os.listdir():
    print(file)
    if os.path.isdir(file):
        os.chdir((file))
        for image in glob.glob('*.tif'):
            
            print(image[:-9])
            new_dir = image[:-6]
            
            if not os.path.isdir(new_dir):os.mkdir(new_dir)
            if image[:-6]==new_dir:
                shutil.move(image,new_dir)
                count+=1
        os.chdir('..')
        print(os.getcwd())   

for file in os.listdir():
    print(file)
    if os.path.isdir(file):
        os.chdir(file)
        homeDir = os.path.join(workingDir,file)
        for imageDir in os.listdir():
            print(imageDir)
            newDir = os.path.join(homeDir,imageDir)
            print(newDir)
            shutil.make_archive(newDir,'zip',newDir)
        os.chdir('..')
              
              
    
        
        # dirAdd= os.path.join(workingDir,file)
        # print(dirAdd)
        # shutil.make_archive(file,'zip',imageDir)
                
        #     if count >= 1 and image[:6] != new_dir:
        #         os.chdir(new_dir)
                
                
                
        #         fileLoc = os.path.join(workingDir,new_dir)
        #         shutil.make_archive(new_dir,'zip',fileLoc)
                
        #         count = 0
        #         os.chdir('.')
            
        # print("in")
        # print(os.getcwd())

    
    # os.chdir('.')
    # print("now in")
    # print(os.getcwd())
    
# for file in os.listdir():
#      print(file)
#      if os.path.isdir(file):
#          os.chdir(file)
#          for image_dir in glob.glob('D3*'):
#              print(image_dir)
#              if os.path.isdir(image_dir):
#                  os.chdir(file)
#                  shutil.make_archive(image_dir, 'zip')
#          os.chdir('..')
             # shutil.make_archive(image_dir, 'zip', root_dir='.')    
    
    
    

