Re: Comparing large amounts of files

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Brad Tilley
Date: Friday, December 11, 2009 - 6:49 pm

On Fri, Dec 11, 2009 at 8:31 PM, Alexander Bochmann <ab@lists.gxis.de> wrote:


I do something similar, but more elaborate, using Python to backup
redundant pics scattered in various folders into one folder... would
need to be modified for name clashes:

already = []
dst = os.getcwd()

paths = ["/usr/local", "/home", "/storage"]

for p in paths:

    for root, dirs, files in os.walk(p):
        for f in files:

            m = hashlib.md5()

            # Get file extension
            ext = os.path.splitext(os.path.join(root, f))[1]

            try:

                # Copy JPG files
                if ext.lower() == ".jpg":
                    fp = open(os.path.join(root, f),'rb')
                    data = fp.read()
                    fp.close()
                    m.update(data)
                    if m.hexdigest() not in already:
                        already.append(m.hexdigest())
                        print "Copying", os.path.join(root,f)
                        shutil.copyfile(os.path.join(root,f),
os.path.join(dst,f))
                    else:
                        print "Already Copied!!!"
...
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Comparing large amounts of files, STeve Andre', (Fri Dec 11, 4:24 pm)
Re: Comparing large amounts of files, Martin Schröder, (Fri Dec 11, 4:32 pm)
Re: Comparing large amounts of files, Noah Pugsley, (Fri Dec 11, 4:36 pm)
Re: Comparing large amounts of files, STeve Andre', (Fri Dec 11, 4:52 pm)
Re: Comparing large amounts of files, anonymous, (Fri Dec 11, 5:11 pm)
Re: Comparing large amounts of files, Paul M, (Fri Dec 11, 5:31 pm)
Re: Comparing large amounts of files, STeve Andre', (Fri Dec 11, 5:55 pm)
Re: Comparing large amounts of files, Alexander Bochmann, (Fri Dec 11, 6:31 pm)
Re: Comparing large amounts of files, STeve Andre', (Fri Dec 11, 6:48 pm)
Re: Comparing large amounts of files, Brad Tilley, (Fri Dec 11, 6:49 pm)
Re: Comparing large amounts of files, Bret S. Lambert, (Fri Dec 11, 7:16 pm)
Re: Comparing large amounts of files, Frank Bax, (Fri Dec 11, 8:22 pm)
Re: Comparing large amounts of files, bofh, (Fri Dec 11, 10:39 pm)
Re: Comparing large amounts of files, Paul M, (Sat Dec 12, 2:47 am)
Re: Comparing large amounts of files, Liviu Daia, (Sat Dec 12, 3:34 pm)
Re: Comparing large amounts of files, Andy Hayward, (Sat Dec 12, 5:38 pm)
Re: Comparing large amounts of files, Nick Bender, (Tue Dec 15, 5:38 pm)
Re: Comparing large amounts of files, J.C. Roberts, (Mon Dec 28, 7:40 pm)
Re: Comparing large amounts of files, J.C. Roberts, (Mon Dec 28, 11:33 pm)
Re: Comparing large amounts of files, J.C. Roberts, (Tue Dec 29, 8:38 pm)