Python Forum
Compare folder A and subfolder B and display files that are in folder A but not in su
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Compare folder A and subfolder B and display files that are in folder A but not in su
#2
for getting list of files, use pathlib instead of os:
from pathlib import Path


home = Path(".")
base = home / "Folder-Oana"

folder1 = base / "extracted"
folder2 = base / "translated"

def get_folder_contents(dirname, filter):
    if filter:
        return [file for file in dirname.iterdir() if file.is_file() and file.suffix == filter]
    else:
        return [file for file in dirname.iterdir() if file.is_file()]

html_files_folder1 = get_folder_contents(dirname=folder1, filter=".html")
html_files_folder2 = get_folder_contents(dirname=folder2, filter=".html")
Note that both paths are sub-directories of Folder-Oana
Reply


Messages In This Thread
RE: Compare folder A and subfolder B and display files that are in folder A but not in su - by Larz60+ - Jan-05-2024, 01:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Deleting Windows temp folder Raysz 7 571 Apr-02-2024, 12:36 PM
Last Post: Raysz
  Help with creating folder and "virtual environment" AudunNilsen 1 275 Mar-21-2024, 04:41 AM
Last Post: deanhystad
Question How to add Python folder in Windows Registry ? Touktouk 1 329 Feb-20-2024, 01:04 PM
Last Post: DeaD_EyE
  Create dual folder on different path/drive based on the date agmoraojr 2 504 Jan-21-2024, 10:02 AM
Last Post: snippsat
  problem in import module from other folder akbarza 5 1,574 Sep-01-2023, 07:48 AM
Last Post: Gribouillis
  Reading a file name fron a folder on my desktop Fiona 4 995 Aug-23-2023, 11:11 AM
Last Post: Axel_Erfurt
  Rename files in a folder named using windows explorer hitoxman 3 796 Aug-02-2023, 04:08 PM
Last Post: deanhystad
  Rename all files in a folder hitoxman 9 1,608 Jun-30-2023, 12:19 AM
Last Post: Pedroski55
  how do I open two instances of visual studio code with the same folder? SuchUmami 3 953 Jun-26-2023, 09:40 AM
Last Post: snippsat
  How i can use categories with folder? AnonymerAlias 2 633 Jun-06-2023, 03:44 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020