Open multiple files with the same extension in a folder
Open multiple files with the same extension in a folder Question: I want to open all files with the same extension (.dat) in the same directory. This is my current code: path = Path(".") # current directory extension = ".dat" file_with_extension = next(path.glob(f"*{extension}")) if file_with_extension: with open(file_with_extension, encoding=’utf-8′) as infile, open(‘462888.dat’, ‘w’, encoding=’utf-8′) as outfile: …