return all items in seq onlya set(seq set(seq would work toobut sets are randomly orderedso any platform-dependent directory order would be lost ""return [item for item in seq if item not in seq def comparedirs(dir dir files =nonefiles =none)""compare directory contentsbut not actual filesmay need bytes listdir arg for undecodable filenames on some platforms ""print('comparing'dir 'to'dir files os listdir(dir if files is none else files files os listdir(dir if files is none else files unique difference(files files unique difference(files files reportdiffs(unique unique dir dir return not (unique or unique true if no diffs def getargs()"args for command-line modetrydir dir sys argv[ :exceptprint('usagedirdiff py dir dir 'sys exit( elsereturn (dir dir command-line args if __name__ ='__main__'dir dir getargs(comparedirs(dir dir given listings of names in two directoriesthis script simply picks out unique names in the first and unique names in the secondand reports any unique names found as differences (that isfiles in one directory but not the otherits comparedirs function returns true result if no differences were foundwhich is useful for detecting differences in callers let' run this script on few directoriesdifferences are detected and reported as names unique in either passed-in directory pathname notice that this is only structural comparison that just checks names in listingsnot file contents (we'll add the latter in moment) :\pp \system\filetoolsdirdiff py :\temp\pp \examples copytemp comparing :\temp\pp \examples to copytemp directory lists are identical :\pp \system\filetoolsdirdiff py :\temp\pp \examples\pp \system comparing :\temp\pp \examples\pp \system to files unique to :\temp\pp \examples\pp \system app complete system programs