PyDocs

Nav

File and Directory Access

dircmp

filecmp

class (source)
  • dircmp(a, b, ignore=None, hide=None, *, shallow=True)
A class that manages the comparison of 2 directories.

dircmp(a, b, ignore=None, hide=None, *, shallow=True)
  A and B are directories.
  IGNORE is a list of names to ignore,
    defaults to DEFAULT_IGNORES.
  HIDE is a list of names to hide,
    defaults to [os.curdir, os.pardir].
  SHALLOW specifies whether to just check the stat signature (do not read
    the files).
    defaults to True.

High level usage:
  x = dircmp(dir1, dir2)
  x.report() -> prints a report on the differences between dir1 and dir2
   or
  x.report_partial_closure() -> prints report on differences between dir1
        and dir2, and reports on common immediate subdirectories.
  x.report_full_closure() -> like report_partial_closure,
        but fully recursive.

Attributes:
 left_list, right_list: The files in dir1 and dir2,
    filtered by hide and ignore.
 common: a list of names in both dir1 and dir2.
 left_only, right_only: names only in dir1, dir2.
 common_dirs: subdirectories in both dir1 and dir2.
 common_files: files in both dir1 and dir2.
 common_funny: names in both dir1 and dir2 where the type differs between
    dir1 and dir2, or the name is not stat-able.
 same_files: list of identical files.
 diff_files: list of filenames which differ.
 funny_files: list of files which could not be compared.
 subdirs: a dictionary of dircmp instances (or MyDirCmp instances if this
   object is of type MyDirCmp, a subclass of dircmp), keyed by names
   in common_dirs.
Changed in 3.13
  • 3.13: Added the shallow parameter.
Members of dircmp

c

common
Files and subdirectories in both a and b.
common_dirs
Subdirectories in both a and b.
common_files
Files in both a and b.
common_funny
Names in both a and b, such that the type differs between the directories, or names for which os.stat() reports an error.

d

diff_files
Files which are in both a and b, whose contents differ according to the class’s file comparison operator.

f

funny_files
Files which are in both a and b, but could not be compared.

l

left
The directory a.
left_list
Files and subdirectories in a, filtered by hide and ignore.
left_only
Files and subdirectories only in a.

r

report
Print (to sys.stdout) a comparison between a and b.
report_full_closure
Print a comparison between a and b and common subdirectories (recursively).
report_partial_closure
Print a comparison between a and b and common immediate subdirectories.
right
The directory b.
right_list
Files and subdirectories in b, filtered by hide and ignore.
right_only
Files and subdirectories only in b.

s

same_files
Files which are identical in both a and b, using the class’s file comparison operator.
subdirs
A dictionary mapping names in common_dirs to dircmp instances (or MyDirCmp instances if this instance is of type MyDirCmp, a subclass of dircmp).
1 Example
>>> from filecmp import dircmp
>>> def print_diff_files(dcmp):
...     for name in dcmp.diff_files:
...         print("diff_file %s found in %s and %s" % (name, dcmp.left,
...               dcmp.right))
...     for sub_dcmp in dcmp.subdirs.values():
...         print_diff_files(sub_dcmp)
...
>>> dcmp = dircmp('dir1', 'dir2')
>>> print_diff_files(dcmp)
from the Python docs
See Also
No see-alsos for filecmp/dircmp
0 Notes
No notes for dircmp