<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by TANNISTHA PAL on Medium]]></title>
        <description><![CDATA[Stories by TANNISTHA PAL on Medium]]></description>
        <link>https://medium.com/@paltannistha?source=rss-6a04f171a801------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*U86lHRLY2mjLYgok</url>
            <title>Stories by TANNISTHA PAL on Medium</title>
            <link>https://medium.com/@paltannistha?source=rss-6a04f171a801------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 19:57:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paltannistha/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Stop Wasting Storage: Find Duplicate Files Using Python]]></title>
            <link>https://python.plainenglish.io/stop-wasting-storage-find-duplicate-files-using-python-8e7fed96c109?source=rss-6a04f171a801------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e7fed96c109</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[file-management-system]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[TANNISTHA PAL]]></dc:creator>
            <pubDate>Thu, 19 Mar 2026 12:20:38 GMT</pubDate>
            <atom:updated>2026-03-29T18:34:02.206Z</atom:updated>
            <content:encoded><![CDATA[<h3>Finding Duplicate Files Using Python</h3><p>It’s quite common to end up with duplicate files on your system — especially when downloading documents, images, or backups multiple times. Over time, these duplicates silently consume storage and make file management harder.</p><p>In this post, we’ll build a simple Python script that identifies duplicate files based on their content, not their filenames.</p><h3>The Problem</h3><p>Duplicate files are not always obvious. Two files can have completely different names but still contain identical data. Traditional methods that rely on filenames won’t catch these cases.</p><p>So, we need a way to compare files based on what they actually contain.</p><h3>The Approach</h3><p>The idea is straightforward:</p><ul><li>Read each file in a given folder</li><li>Generate a unique hash value for its content</li><li>Store the hash in a dictionary</li><li>If the same hash appears again, we’ve found a duplicate</li></ul><p>We use hashing because it provides a consistent “fingerprint” of a file’s content. If two files have the same hash, they are almost certainly identical.</p><h3>Implementation</h3><p>Here’s the Python code:</p><pre>import os<br>import hashlib</pre><pre># function to calculate file hash<br>def get_file_hash(file_path):<br>    hash_obj = hashlib.sha256()</pre><pre>    try:<br>        with open(file_path, &#39;rb&#39;) as file:<br>            while chunk := file.read(4096):<br>                hash_obj.update(chunk)<br>    except Exception:<br>        print(f&quot;Error reading: {file_path}&quot;)<br>        return None</pre><pre>    return hash_obj.hexdigest()</pre><pre># function to find duplicate files<br>def find_duplicates(folder_path):<br>    hash_map = {}</pre><pre>    for root, dirs, files in os.walk(folder_path):<br>        for file in files:<br>            file_path = os.path.join(root, file)</pre><pre>            file_hash = get_file_hash(file_path)<br>            if file_hash is None:<br>                continue</pre><pre>            if file_hash in hash_map:<br>                hash_map[file_hash].append(file_path)<br>            else:<br>                hash_map[file_hash] = [file_path]</pre><pre>    found = False<br>    for file_list in hash_map.values():<br>        if len(file_list) &gt; 1:<br>            if not found:<br>                print(&quot;\nDuplicate files found:\n&quot;)<br>                found = True</pre><pre>            for file in file_list:<br>                print(file)<br>            print()</pre><pre>    if not found:<br>        print(&quot;No duplicates found.&quot;)</pre><pre># run the script<br>folder = input(&quot;Enter folder path: &quot;)<br>find_duplicates(folder)</pre><h3>How It Works</h3><ul><li>os.walk() goes through the folder and all its subfolders.</li><li>Each file is opened in binary mode and read in chunks to avoid memory issues with large files.</li><li>A SHA-256 hash is generated for each file.</li><li>Files with the same hash are grouped together.</li></ul><h3>Example</h3><p>Consider this folder structure:</p><pre>test_folder/<br>├── file1.txt<br>├── file_copy.txt<br>└── subfolder/<br>    └── file1_backup.txt</pre><p>If all three files have identical content, the script will group and print them as duplicates.</p><h3>Why This Works Well</h3><ul><li>It doesn’t depend on filenames</li><li>It handles nested directories automatically</li><li>It scales to large files by reading them in chunks</li></ul><h3>Possible Improvements</h3><p>This script can be extended in several ways:</p><ul><li>Compare file sizes before hashing to improve performance</li><li>Add an option to delete or move duplicate files</li><li>Save the results to a file for later review</li><li>Build a simple user interface</li></ul><h3>Conclusion</h3><p>This is a small but practical project that demonstrates file handling, hashing, and efficient data structures in Python. It’s also immediately useful for cleaning up storage and organizing files.</p><p>If you’re exploring Python projects or preparing for interviews, this is a good example of solving a real-world problem with a clean approach.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e7fed96c109" width="1" height="1" alt=""><hr><p><a href="https://python.plainenglish.io/stop-wasting-storage-find-duplicate-files-using-python-8e7fed96c109">Stop Wasting Storage: Find Duplicate Files Using Python</a> was originally published in <a href="https://python.plainenglish.io/">Python in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>