
# https://www.globalsino.com/ICs/
# Check if new files in the folder

import os
from os.path import exists
import csv
from pandas import *

# os.path.join(Path, "TestScreenshot22" + "." + "png")

theFiles = r"C:\GlobalSino2\ICs\theFileList.csv"
if exists(theFiles) == True:
    print("There is file in the folder!")    
else:
    EM_file = open(theFiles, 'a')
    EM_file.write("The files")
    EM_file.close()
    print("Created a new file with the file name!")

# reading CSV file
data = read_csv(theFiles)
# converting column data to list
theList = data["The files"].tolist()

print(theList)

mypath = r"C:\0Python\TestImages"
for root, dirs, files in os.walk(mypath):
    for file in files:
        filePath = os.path.join(root, file)
        if filePath.endswith(".png") == True:
            # print(filePath)
            if filePath not in theList:
                # "a": append a row, "w": overwrite the original csv file
                with open (theFiles, 'a', newline ='') as my_csv_file:
                    My_csv_writer = csv.writer(my_csv_file)
                    My_csv_writer.writerow ([filePath])

print("\n New file list is: ")
 
# reading CSV file
dataNew = read_csv(theFiles)
# converting column data to list
NewList = dataNew["The files"].tolist()
print(NewList)

print("\n") 
if NewList == theList:
    print("No new specific files in the folder!")
else:
    print("New specific files in the folder!")
