Python applet compares the differences between catalogs

Source: Internet
Author: User

To compare differences between catalogs:

I only compare by name, if the file name of the directory is the same, but the contents of different scripts are considered to be the same file

II There is no round-robin comparison for directories below the directory, just comparing the name of the directory

import sys, osdef difference (seq1, seq2): "" returns only items in seq1 "" "return [i        TEM for item in SEQ1 if Item not in Seq2]def Reportdiff (unique1, unique2, dir1, dir2): if not (unique1 or unique2): Print ("dir lists is Identical") else:if unique1:print ("file unique to", dir1) for I TEM in Unique1:print (' ... ', item) if unique2:print ("file unique to", dir2) F or item in Unique2:print ("...", Item) def comparedirs (dir1, dir2): print ("comparing {0} to {1}". format (d ir1, dir2)) if not (os.path.isdir (dir1) and os.path.isdir (dir2)): return else:files1 = Os.listdir (dir 1) files2 = os.listdir (dir2) unique1 = Difference (files1, files2) unique2 = Difference (files2, files1 ) Reportdiff (unique1, unique2, dir1, dir2) if __name__ = = ' __main__ ': comparedirs ('.. /testdir ', '. /testdir1 ') 

  

Python applet compares the differences between catalogs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.