Skip to content

Instantly share code, notes, and snippets.

@stucka
Created August 30, 2016 02:38
Show Gist options
  • Save stucka/383836cd013a86e8aa6173b5338f47c3 to your computer and use it in GitHub Desktop.
Save stucka/383836cd013a86e8aa6173b5338f47c3 to your computer and use it in GitHub Desktop.
Find files from one directory tree that aren't in another
import os
sourcedir = "h:\\D\\video"
destdir = "d:\\video"
def getfilelist(dirname):
filelist = {}
count = 0
for root, dirs, files in os.walk(dirname):
for file in files:
#filelist.append(os.path.join(root, file).replace(dirname + '\\', ""))
filelist[file] = os.path.join(root, file).replace(dirname + '\\', '')
count += 1
print(str(count))
return filelist
sourcefiles = getfilelist(sourcedir)
destfiles = getfilelist(destdir)
print(str(len(sourcefiles)) + " files found in " + sourcedir)
print(str(len(destfiles)) + " files found in " + destdir)
for file in sourcefiles:
if file not in destfiles:
#print(file + " at " + sourcefiles[file])
#print("copy " + sourcedir.replace("\\", "\") + "\\" + sourcefiles[file] + ' d:\\video\\missing\\')
print("copy /z \"" + sourcedir + "\\" + sourcefiles[file] + "\" " + "\"" + destdir + "\"")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment