Jan-05-2024, 11:59 AM
Create a code that compares c:\Folder-Oana\extracted\ and c:\Folder-Oana\extracted\translated\ and shows me the files that are in the first folder, but not in the second. So, compare folder A and subfolder B and display files that are in folder A but not in subfolder B. So I have 1880 html files in folder A and only 50 html files in FOLDER B. So, cod must show me each files, the different between 1880 - 50.
This is my code (2 versions). I try with ChatGPT another, more ways, but didn't work. I believe the problem is that there are FOLDER + SUBFOLDER, not different folders with no other subfolders in it.
Version 1
This is my code (2 versions). I try with ChatGPT another, more ways, but didn't work. I believe the problem is that there are FOLDER + SUBFOLDER, not different folders with no other subfolders in it.
Version 1
import os
folder1 = r"C:\Folder-Oana\extracted"
folder2 = r"C:\Folder-Oana\extracted\translated"
# Obține lista de fișiere HTML din fiecare folder
html_files_folder1 = [f.lower() for f in os.listdir(folder1) if f.lower().endswith('.html')]
html_files_folder2 = [f.lower() for f in os.listdir(folder2) if f.lower().endswith('.html')]
# Găsește diferențele între cele două liste de fișiere
missing_files = list(set(html_files_folder1) - set(html_files_folder2))
# Afișează fișierele care lipsesc
if missing_files:
print("Fișierele HTML care se găsesc în folderul 1, dar nu în folderul 2, sunt:")
for filename in missing_files:
print(filename)
else:
print("Nu există fișiere HTML care se găsesc în folderul 1, dar nu în folderul 2.")Version 2import os
folder1 = r'C:\Folder-Oana\extracted\translated'
folder2 = r'C:\Folder-Oana\extracted'
# Funcție pentru a returna lista de fișiere HTML dintr-un folder
def get_html_files(folder):
html_files = []
for root, dirs, files in os.walk(folder):
for file in files:
if file.lower().endswith('.html'):
html_files.append(file)
return html_files
# Obține lista de fișiere HTML pentru fiecare folder
html_files_folder1 = get_html_files(folder1)
html_files_folder2 = get_html_files(folder2)
# Verifică fișierele care se găsesc în folderul 1, dar nu în folderul 2
missing_files = [file for file in html_files_folder1 if file not in html_files_folder2]
# Afișează fișierele și folderul corespunzător în care se găsesc
for file in missing_files:
if file in html_files_folder1:
print(f"Fișierul {file} se găsește în folderul {folder1}")
if file in html_files_folder2:
print(f"Fișierul {file} se găsește în folderul {folder2}")
