Below is the program to Create empty files with same names and different extensions present in a specific directory in python. Here is the code:
import glob
import os
path = 'C:\\Users\\Test\\Documents\\2025\\August\\6 Aug\\Email\\'
add_extension = ".ok"
i=1
for i, filename in enumerate(glob.glob(path + '*.xml')):
new_filename = filename + add_extension
try:
with open(new_filename, 'w') as f:
pass # No content is written, so the file remains empty
print(f"Empty file '{new_filename}' created successfully.")
except IOError as e:
print(f"Error creating file: {e}")
Comments
Post a Comment