Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, json, time, openpyxl
- from PIL import Image, ExifTags
- folder_path = input("Kérlek add meg a kilistázandó mappát!")
- file_list = [ os.path.join( folder_path, f ) for f in os.listdir(folder_path) if os.path.isfile( os.path.join( folder_path, f ) ) ]
- file_data = {}
- for f in file_list:
- file_name = os.path.basename(f)
- file_size = os.path.getsize(f)
- file_date = time.ctime(os.path.getmtime(f))
- file_data[f] = {"name":file_name, "size":int(file_size/1024), "creation_date":file_date }
- get_folder = f"{file_data}"
- # print(file_name, file_size/1024, "KB",file_date)
- with open('my_text.txt', 'a') as f:
- f.write(get_folder)
- with open("file_data.json", "w") as f:
- json.dump(file_data, f)
- workbook = openpyxl.Workbook()
- sheet = workbook.active
- sheet.column_dimensions["A"].width = 30
- sheet.column_dimensions["B"].width = 30
- sheet.column_dimensions["C"].width = 30
- sheet[f'A1'] = "File"
- sheet[f'B1'] = "Méret"
- sheet[f'C1'] = "Dátum"
- for index, f in enumerate( file_list ):
- file_name = os.path.basename(f)
- file_size = os.path.getsize(f)
- file_date = time.ctime(os.path.getmtime(f))
- sheet[f'A{index + 3}'] = file_name
- sheet[f'B{index + 3}'] = file_size
- sheet[f'c{index + 3}'] = file_date
- img = Image.open(f)
- exif_data = img._getexif()
- if not exif_data:
- print(f"WARNING: No exif data for {f}")
- continue
- for k,v in exif_data.items():
- exif_name = ExifTags.TAGS.get(k)
- if exif_name and exif_name == "DateTime":
- sheet[f'C{index + 3}'] = v
- workbook.save(filename="file_data.xlsx")
- print( "A mappa",len( os.listdir(folder_path) ),"fájlt tartalmaz!" )
- time.sleep(5)
Advertisement
Add Comment
Please, Sign In to add comment