Duplicate File Finder Script

/images/duplicate-file-finder-script/duplicate-file-finder-script.gif

The following cross-platform Python script lets you find duplicate files within a directory tree. Files are considered duplicates when they have the same name and content. First, the script walks through the directory tree by using the os.walk() standard function and stores the MD5 digest of every file found in the process. The threading module is used to spawn multiple workers (as much as available cores) in order to speed up this process. Second, file names and MD5 digests are compared to find duplicate files and write the results into duplicate_files.txt.

The code is simple, type-annotated (checked against mypy) and much commented so it can be easily customized. Python 3.9 or greater is required.

Read more…

Find Biggest File in Directory Tree

/images/find-biggest-file-in-directory-tree/find-biggest-file.gif

The following cross-platform Python script allows you to search for the biggest file within a directory and all its subfolders (the search is recursive). The directory path must be passed as the first argument when invoking the script. Additionally, a second argument indicating a file extension can optionally be passed to limit the search.

Read more…

Display Image in Tk (tkinter)

An image can be loaded from disk and displayed within a label (tk.Label or ttk.Label) by using the tk.PhotoImage class:

import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title("Display Image in Tk")
root.geometry("400x300")
# Load image from disk.
image = tk.PhotoImage(file="image.png")
# Display it within a label.
label = ttk.Label(image=image)
label.pack()
root.mainloop()

Read more…