in order here finding directory differences before we start codingthe first thing we need to clarify is what it means to compare two directory trees if both trees have exactly the same branch structure and depththis problem reduces to comparing corresponding files in each tree in generalthoughthe trees can have arbitrarily different shapesdepthsand so on more generallythe contents of directory in one tree may have more or fewer entries than the corresponding directory in the other tree if those differing contents are filenamesthere is no corresponding file to compare withif they are directory namesthere is no corresponding branch to descend through in factthe only way to detect files and directories that appear in one tree but not the other is to detect differences in each level' directory in other wordsa tree comparison algorithm will also have to perform directory comparisons along the way because this is nested and simpler operationlet' start by coding and debugging single-directory comparison of filenames in example - example - pp \system\filetools\dirdiff py ""###############################################################################usagepython dirdiff py dir -path dir -path compare two directories to find files that exist in one but not the other this version uses the os listdir function and list difference note that this script checks only filenamesnot file contents--see diffall py for an extension that does the latter by comparing read(results ###############################################################################""import ossys def reportdiffs(unique unique dir dir )""generate diffs report for one dirpart of comparedirs output ""if not (unique or unique )print('directory lists are identical'elseif unique print('files unique to'dir for file in unique print('fileif unique print('files unique to'dir for file in unique print('filedef difference(seq seq )comparing directory trees