Python Forum
[PySimpleGUI] New GUI Package. Customize with ease
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PySimpleGUI] New GUI Package. Customize with ease
#6
Demo_DuplicateFileFinder.py gives an error on my Mint18(Ubuntu 16.04) on

    msg = f'{total} Files processed\n'\
          f'{dup_count} Duplicates found\n'
Quote: msg = f'{total} Files processed\n'\
^
SyntaxError: invalid syntax

this works for me

    msg = "%s%s%s%s" % (total , ' Files processed\n', dup_count, ' Duplicates found\n')

to see the names of the files

import hashlib
import os
import PySimpleGUI as sg


# ====____====____==== FUNCTION DeDuplicate_folder(path) ====____====____==== #
# Function to de-duplicate the folder passed in                               #
# --------------------------------------------------------------------------- #
def FindDuplicatesFilesInFolder(path):
    shatab = []
    total = 0
    small_count, dup_count, error_count = 0,0,0
    pngdir = path
    dup_files = []
    if not os.path.exists(path):
        sg.MsgBox('Duplicate Finder', '** Folder doesn\'t exist***', path)
        return
    pngfiles = os.listdir(pngdir)
    total_files = len(pngfiles)
    for idx, f in enumerate(pngfiles):
        if not sg.EasyProgressMeter('Counting Duplicates', idx + 1, total_files, 'Counting Duplicate Files'):
            break
        total += 1
        fname = os.path.join(pngdir, f)
        if os.path.isdir(fname):
            continue
        x = open(fname, "rb").read()

        m = hashlib.sha256()
        m.update(x)
        f_sha = m.digest()
        if f_sha in shatab:
            # uncomment next line to remove duplicate files
            # os.remove(fname)
            dup_count += 1
            # sg.Print(f'Duplicate file - {f}')    # cannot current use sg.Print with Progress Meter
            print("Duplicate file:",  f) 
            dup_files.append(f)
            continue
        shatab.append(f_sha)

    msg = "%s%s%s%s%s%s" % (total , ' Files processed\n', dup_count, ' Duplicates found\n', '\nDuplicate Files:\n', '\n'.join(dup_files))
    sg.MsgBox('Duplicate Finder Ended', msg)

# ====____====____==== Pseudo-MAIN program ====____====____==== #
# This is our main-alike piece of code                          #
#   + Starts up the GUI                                         #
#   + Gets values from GUI                                      #
#   + Runs DeDupe_folder based on GUI inputs                    #
# ------------------------------------------------------------- #
if __name__ == '__main__':

    source_folder = None
    rc, source_folder = sg.GetPathBox('Duplicate Finder - Count number of duplicate files', 'Enter path to folder you wish to find duplicates in')
    if rc is True and source_folder is not None:
        FindDuplicatesFilesInFolder(source_folder)
    else:
        sg.MsgBoxCancel('Cancelling', '*** Cancelling ***')
    exit(0)
Reply


Messages In This Thread
RE: [PySimpleGUI] New GUI Package. Customize with ease - by Axel_Erfurt - Aug-03-2018, 11:02 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PySimpleGUI Try Except jamesaarr 1 2,024 Nov-18-2021, 02:02 PM
Last Post: jamesaarr
  [PySimpleGUI]Install package on Conda not up-to-date RayJohnson 4 4,614 Jan-22-2020, 11:17 PM
Last Post: RayJohnson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020