Dircmp
Author: s | 2025-04-24
directory comparison with minimal output for huge collections - dircmp/dircmp at master bibermann/dircmp
dircmp/dircmp at master bibermann/dircmp - GitHub
Dircmp(1) General Commands Manual dircmp(1)Name dircmp - directory comparisonSyntax dircmp [ -d ] [ -s ] [ -wn ] dir...Description The command examines dir1 and dir2 and generates tabulated information about the contents of the directories. Listings of files that are unique to each directory are generated for all the options. If no option is entered, a list is output indicating whether the filenames common to both directories have the same contents. This command is supplied for X/OPEN compliance. The same results are available from which produces results more quickly and effectively.Options -d Compares the contents of files with the same name in both directories and output a list telling what must be changed in the two files to bring them into agreement. The list format is described in -s Suppresses messages about identical files. -wn Changes the width of the output line to n characters. The default width is 72.See Also cmp(1), diff(1). dircmp(1)
Free dircmp Download - dircmp for Windo
11.5.1 The dircmp class 11.5.1 The dircmp class dircmp instances are built using this constructor: class dircmp( a, b[, ignore[, hide]])Construct a new directory comparison object, to compare thedirectories a and b. ignore is a list of names toignore, and defaults to ['RCS', 'CVS', 'tags']. hide is alist of names to hide, and defaults to [os.curdir, os.pardir].The dircmp class provides the following methods:Print (to sys.stdout) a comparison between a and b. report_partial_closure( )Print a comparison between a and b and common immediatesubdirectories.Print a comparison between a and b and common subdirectories (recursively).The dircmp offers a number of interesting attributes that maybe used to get various bits of information about the directory treesbeing compared.Note that via __getattr__() hooks, all attributes arecomputed lazily, so there is no speed penalty if only thoseattributes which are lightweight to compute are used.left_listFiles and subdirectories in a, filtered by hide andignore.right_listFiles and subdirectories in b, filtered by hide andignore.commonFiles and subdirectories in both a and b.left_onlyFiles and subdirectories only in a.right_onlyFiles and subdirectories only in b.common_dirsSubdirectories in both a and b.common_filesFiles in both a and bcommon_funnyNames in both a and b, such that the type differs betweenthe directories, or names for which os.stat() reports anerror.same_filesFiles which are identical in both a and b.diff_filesFiles which are in both a and b, whose contents differ.funny_filesFiles which are in both a and b, but could not becompared.subdirsA dictionary mapping names in common_dirs todircmp objects.Release 2.5, documentation updated on 19th September, 2006.See About this document... for information on suggesting changes.Free dircmp インストール Download - dircmp インストール for
前情提示: 测试代码中,右尖括号(>)表示命令行中输入的命令; 单独一行并以井字符(#)开头的为输出内容; 库的导入仅在本文的第一个测试代码中展现,其他代码块均省略库的导入代码。系统类型: Windows 10python 版本: Python 3.9.0filecmp 模块可以用于文件与文件之间或目录与目录之间的比较。并且可以通过设置参数来选取多种不同用时和不同准确性的方案。filecmp 模块在进行文件或目录对比时,最终仅能返回是否相等这一结果。某些场景需要更加详细的结果说明,可以使用 difflib 标准库。快捷函数filecmp.cmp(f1, f2, shallow=True)参数: f1, f2: 要进行比较的两个文件 shallow: 关键字参数, 参数值为布尔值, 默认为 True; 如果为 True, 则判断两文件需要具有相同的 os.stat() 签名才会认为是相等的; 如果为 False, 则比较两文件的内容;返回值: 布尔值, 两个文件是否相等比较 f1 和 f2 的文件,如果它们似乎相等则返回 True,否则返回 False。在官方文档中用上了 '似乎' 一词,这让人感觉有什么隐秘的信息文档上没有表达出来。import filecmpimport os'''本次测试代码中存在 4 个待对比文件, 其中 文件1 与 文件2 内容不同, 文件3 与 文件4 内容相同'''print(os.stat('文件1'))print(os.stat('文件2'))print(filecmp.cmp('文件1', '文件2', shallow=True))print(filecmp.cmp('文件1', '文件2', shallow=False))# os.stat_result(st_mode=33206, st_ino=1407374883609775, st_dev=3098197482, st_nlink=1, st_uid=0, st_gid=0, st_size=4, st_atime=1611109066, st_mtime=1611109066, st_ctime=1611043715)# os.stat_result(st_mode=33206, st_ino=1688849860320432, st_dev=3098197482, st_nlink=1, st_uid=0, st_gid=0, st_size=4, st_atime=1611045689, st_mtime=1611045689, st_ctime=1611043722)# True# True当比较内容相同的 文件1 与 文件2 时,参数 shallow 无论设置为 True 还是 False 结果都是 True。按照文档所述,文件1 和 文件2 的 os.stat() 是不相同的,当参数 shallow 设置为 True 时,根据两个文件的 os.stat() 最终应该得到 False。为什么实际运行和文档描述不同呢?查阅一些资料后,找到了一个比较合理的解释,当参数 shallow 设置为 True,那么 os.stat() 相同的会直接被视为相等,当两个文件的 os.stat() 不同时,依旧会对比文件中的内容。另外,此函数会缓存比较结果,在下次比较时直接返回缓存结果。如果文件的 os.stat() 变化了,也就是文件被修改了,缓存自动失效。缓存也能用下文中的 filecmp.clear_cache() 函数清除。filecmp.cmpfiles(dir1, dir2, common, shallow=True)参数: dir1, dir2: 目录 common: 需要对比的文件名列表 shallow: 关键字参数, 参数值为布尔值, 默认为 True; 如果为 True, 则判断两文件需要具有相同的 os.stat() 签名才会认为是相等的; 如果为 False, 则比较两文件的内容;返回值: 元组, 包含三个类型为列表的元素.比较两个目录下的指定文件,返回对比结果,返回值是包含三个类型为列表的元素的元组。'''文件目录如下, 其中, 两个目录内的 文件a 内容相同, 文件c 内容不同- 目录1 - 文件a - 目录b - 文件c - 文件d- 目录2 - 文件a - 目录b - 文件c''''''对比两目录下的文件'''print(filecmp.cmpfiles('目录1', '目录2', ['文件a', '目录b/文件c', '文件d']))# (['文件a'], ['目录b/文件c'], ['文件d'])参数 common 列举要对比的文件名,分别对比两个目录下的同名文件,如果两个文件相同,则加入返回值的第一个元素内; 如果两个文件内容不同,则加入返回值的第二个元素内; 如果文件无权限读取或者文件在任一目录内缺失,则加入返回值的第三个元素内;参数 shallow 与上文中 filecmp.cmp() 函数意义相同。filecmp.clear_cache()清除 filecmp 缓存。一般情况下,文件修改后,文件的 os.stat() 自然会改变,缓存也会自动失效。但是如果文件被过快的修改,以至于超过底层文件系统记录修改时间的精度时,那么此后的文件对比将可能会出现问题,此函数就是为了解决这个问题。但是,这种文件过快的修改不知道怎样测试出来? 大家有知道的吗?dircmp 类class filecmp.dircmp(a, b, ignore=None, hide=None)参数: a, b: 目录 ignore: 关键字参数, 需要忽略的文件名列表, 默认为 filecmp.DEFAULT_IGNORES hide: 关键字参数, 需要隐藏的文件名列表, 默认为 [os.curdir, os.pardir]创建一个用于比较两个目录的目录比较对象。参数 ignore 可忽略指定的文件名,hide 可隐藏指定的文件名。print(filecmp.DEFAULT_IGNORES)# ['RCS', 'CVS', 'tags', '.git', '.hg', '.bzr', '_darcs', '__pycache__']print(os.curdir)# .print(os.pardir)# ..dircmp 类中有许多属性,这里使用测试代码直接展示:dircmp_test = filecmp.dircmp('目录1', '目录2')'''第一个(相对左边)参数, 也是第一个目录的名称'''print(dircmp_test.left)# 目录1'''第二个(相对右边)参数, 也是第二个目录的名称'''print(dircmp_test.right)# 目录2'''经参数 hide 与参数 ignore 过滤后, 第一个目录内的所有文件与子目录'''print(dircmp_test.left_list)# ['文件a', '文件d', '目录b']'''经参数 hide 与参数 ignore 过滤后, 第二个目录内的所有文件与子目录'''print(dircmp_test.right_list)# ['文件a', '目录b']'''同时存在两个目录下的文件与子目录'''print(dircmp_test.common)# ['文件a', '目录b']'''仅存在第一个目录下的文件与子目录'''print(dircmp_test.left_only)# ['文件d']'''仅存在第二个目录下的文件与子目录'''print(dircmp_test.right_only)# []'''同时存在两个目录下的子目录'''print(dircmp_test.common_dirs)# ['目录b']'''将 common_dirs 属性值映射为 dircmp 对象的字典'''print(dircmp_test.subdirs)# {'目录b': }'''同时存在两个目录下的文件'''print(dircmp_test.common_files)# ['文件a']'''在两个目录中类型不同的名字,或者那些 os.stat() 报告错误的名字'''print(dircmp_test.common_funny)# []'''在两个目录下, 使用类的比较操作符相同的文件'''print(dircmp_test.same_files)#. directory comparison with minimal output for huge collections - dircmp/dircmp at master bibermann/dircmpDirCmp - ian.jeffray.co.uk
NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | USAGE | ENVIRONMENT VARIABLES | EXIT STATUS | ATTRIBUTES | SEE ALSONAMEdircmp- directory comparisonSYNOPSISdircmp [-ds] [-w n] dir1 dir2DESCRIPTIONThe dircmp command examines dir1and dir2 and generates various tabulated informationabout the contents of the directories. Listings of files that are uniqueto each directory are generated for all the options. If no option is entered,a list is output indicating whether the file names common to both directorieshave the same contents.OPTIONSThe following options are supported:-dCompares the contents of files with thesame name in both directories and output a list telling what must be changedin the two files to bring them into agreement. The list format is describedin diff(1).-sSuppressesmessages about identical files.-w nChanges the width of the output line to ncharacters. The default width is 72.OPERANDSThe following operands are supported:dir1dir2A path name of a directory to be compared.USAGESee largefile(5)for the description of the behavior of dircmp when encounteringfiles greater than or equal to 2 Gbyte ( 231bytes).ENVIRONMENT VARIABLESSee environ(5)for descriptions of the following environment variables that affect theexecution of dircmp: LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH.EXIT STATUSThe following exit values are returned:0Successful completion.>0An error occurred. (Differences in directory contents are not considerederrors.)ATTRIBUTESSee attributes(5)for descriptions of the following attributes: ATTRIBUTE TYPE ATTRIBUTE VALUE Availability SUNWesuSEE ALSOcmp(1), diff(1), attributes(5), environ(5), largefile(5)SunOS 5.9 Last Revised 1 Feb 1995NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | USAGE | ENVIRONMENT VARIABLES | EXIT STATUS | ATTRIBUTES | SEE ALSOFree dircmp 1.0 Download - dircmp 1.0 for Windows - UpdateStar
源代码: Lib/filecmp.pyfilecmp 模块定义了用于比较文件及目录的函数,并且可以选取多种关于时间和准确性的折衷方案。对于文件的比较,另见 difflib 模块。filecmp 模块定义了如下函数:filecmp.cmp(f1, f2, shallow=True)¶比较名为 f1 和 f2 的文件,如果它们似乎相等则返回 True ,否则返回 False 。如果 shallow 为真,那么具有相同 os.stat() 签名的文件将会被认为是相等的。否则,将比较文件的内容。需要注意,没有外部程序被该函数调用,这赋予了该函数可移植性与效率。该函数会缓存过去的比较及其结果,且在文件的 os.stat() 信息变化后缓存条目失效。所有的缓存可以通过 clear_cache() 清除。filecmp.cmpfiles(dir1, dir2, common, shallow=True)¶比较在两个目录 dir1 和 dir2 中,由 common 所确定名称的文件。返回三组文件名列表: match, mismatch, errors 。 match 含有相匹配的文件, mismatch 含有那些不匹配的,然后 errors 列出那些未被比较文件的名称。如果文件不存在于两目录中的任一个,或者用户缺少读取它们的权限,又或者因为其他的一些原因而无法比较,那么这些文件将会被列在 errors 中。参数 shallow 具有同 filecmp.cmp() 一致的含义与默认值。例如, cmpfiles('a', 'b', ['c', 'd/e']) 将会比较 a/c 与 b/c 以及 a/d/e 与 b/d/e 。 'c' 和 'd/e' 将会各自出现在返回的三个列表里的某一个列表中。filecmp.clear_cache()¶清除 filecmp 缓存。如果一个文件过快地修改,以至于超过底层文件系统记录修改时间的精度,那么该函数可能有助于比较该类文件。3.4 新版功能.dircmp 类¶class filecmp.dircmp(a, b, ignore=None, hide=None)¶创建一个用于比较目录 a 和 b 的新的目录比较对象。 ignore 是需要忽略的文件名列表,且默认为 filecmp.DEFAULT_IGNORES 。 hide 是需要隐藏的文件名列表,且默认为 [os.curdir, os.pardir] 。dircmp 类如 filecmp.cmp() 中所描述的那样对文件进行 shallow 比较。dircmp 类提供以下方法:report()¶将 a 与 b 之间的比较打印(到 sys.stdout )。report_partial_closure()¶打印 a 与 b 及共同直接子目录的比较结果。report_full_closure()¶打印 a 与 b 及共同子目录比较结果(递归地)。dircmp 类提供了一些有趣的属性,用以得到关于参与比较的目录树的各种信息。需要注意,通过 __getattr__() 钩子,所有的属性将会惰性求值,因此如果只使用那些计算简便的属性,将不会有速度损失。left¶目录 a 。right¶目录 b 。left_list¶经 hide 和 ignore 过滤,目录 a 中的文件与子目录。right_list¶经 hide 和 ignore 过滤,目录 b 中的文件与子目录。common¶同时存在于目录 a 和 b 中的文件和子目录。left_only¶仅在目录 a 中的文件和子目录。right_only¶仅在目录 b 中的文件和子目录。common_dirs¶同时存在于目录 a 和 b 中的子目录。common_files¶同时存在于目录 a 和 b 中的文件。common_funny¶在目录 a 和 b 中类型不同的名字,或者那些 os.stat() 报告错误的名字。same_files¶在目录 a 和 b 中使用类的文件比较操作符相等的文件。diff_files¶在目录 a 和 b 中,根据类的文件比较操作符判定内容不等的文件。funny_files¶在目录 a 和 b 中无法比较的文件。subdirs¶一个将 common_dirs 中名称映射为 dircmp 对象的字典。filecmp.DEFAULT_IGNORES¶3.4 新版功能.默认被 dircmp 忽略的目录列表。下面是一个简单的例子,使用 subdirs 属性递归搜索两个目录以显示公共差异文件:>>> 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)DIRCMP(1) - man.omnios.org
Contenido del directorio b (filtrado por ignore y hide) common: lista de archivos y directorios comunes left_only: lista de archivos y directorios que sólo aparecen en a right_only: lista archivos y directorios que sólo aparecen en b common_dirs: subdirectorios comunes common_files: archivos comunes common_funny: archivos y directorios comunes con errores same_files: archivos idénticos tanto en a y b utilizando el operador de comparación de clase. diff_files: archivos diferentes tanto en a y b utilizando el operador de comparación de clase.funny_files: archivos que están tanto en a y b pero que no pueden ser comparados. subdirs: diccionario de subdirectorios con objetos de comparaciónDesde Python 3.4 el atributo filecmp.DEFAULT_IGNORES devuelve la lista de directorios ignorados por defecto en la clase dircmp.A continuación, un ejemplo basado en los anteriores que utiliza la clase dircmp para comparar los directorios 'dir1' y 'dir2'; en el que se obtiene mucha información gracias a los métodos y atributos disponibles:# Dentro de los directorios de los ejemplos anteriores se # crea un directorio llamado 'dir3' y se copia a este un # archivo diferente a cada uno de ellos:os.mkdir("dir1/dir3")os.mkdir("dir2/dir3")shutil.copy2("arch1.txt", "dir1/dir3/arch1.txt")shutil.copy2("arch2.txt", "dir2/dir3/arch2.txt")# Se comparan los directorios 'dir1' y 'dir2'resultado = filecmp.dircmp('dir1', 'dir2') # Se muestran distintos resultadosresultado.report()resultado.report_partial_closure()resultado.report_full_closure()'''Resultado de report()---------------------diff dir1 dir2Only in dir1 : ['arch3.txt']Identical files : ['arch1.txt']Differing files : ['arch2.txt']Common subdirectories : ['dir3']Resultado de report_partial_closure()-------------------------------------diff dir1 dir2Only in dir1 : ['arch3.txt']Identical files : ['arch1.txt']Differing files : ['arch2.txt']Common subdirectories : ['dir3']diff dir1/dir3 dir2/dir3Only in dir1/dir3 : ['arch1.txt']Only in dir2/dir3 : ['arch2.txt']Resultado de report_full_closure()----------------------------------diff dir1 dir2Only in dir1 : ['arch3.txt']Identical files : ['arch1.txt']Differing files : ['arch2.txt']Common subdirectories : ['dir3']diff dir1/dir3 dir2/dir3Only in dir1/dir3 : ['arch1.txt']Only in dir2/dir3 : ['arch2.txt']'''# Para finalizar, se accede a los atributos de la clase dircmpprint(resultado.left) # dir1print(resultado.right) # dir2print(resultado.left_list) #'arch1.txt','arch2.txt','arch3.txt','dir3'print(resultado.right_list) # 'arch1.txt', 'arch2.txt', 'dir3']print(resultado.common) # 'dir3', 'arch1.txt', 'arch2.txt']print(resultado.left_only) # ['arch3.txt']print(resultado.right_only) # [] print(resultado.common_dirs) # ['dir3']print(resultado.common_files) # ['arch1.txt', 'arch2.txt']print(resultado.common_funny) # []print(resultado.same_files) # ['arch1.txt']print(resultado.diff_files) # ['arch2.txt']print(resultado.funny_files) # []print(resultado.subdirs) #{'dir3':filecmp.dircmp object at 0xb6f82f0c}print(resultado.subdirs['dir3'].report())'''Salida------diff dir1/dir3 dir2/dir3Only in dir1/dir3 : ['arch1.txt']Only in dir2/dir3 : ['arch2.txt']None'''Relacionado:Difflib: encontrando las diferenciasExplorando directorios con os.listdir, os.walk y os.scandirFiltrando archivos y directorios con glob y fnmatchCopiar, mover y borrar archivos/directorios con shutilIr al índice deldircmp Command - University of Alberta
DirCmp 34.1 Crack+ Serial Key Free Download [32|64bit] (Updated 2022)DirCmp is a straightforward command-line tool designed to help you compare two folders and identify files that are either missing or have been modified since the last backup. It is relatively easy to use, and it allows you to employ several filters to refine the scan.Winapp2kDirCmp is a useful command-line utility that can help you compare two folders and identify differences in content. It offers a decent feature set, and it should prove to be very straightforward if you are comfortable using the command console.DirCmp Description:DirCmp is a straightforward command-line tool designed to help you compare two folders and identify files that are either missing or have been modified since the last backup. It is relatively easy to use, and it allows you to employ several filters to refine the scan.Winapp2kDirCmp is a useful command-line utility that can help you compare two folders and identify differences in content. It offers a decent feature set, and it should prove to be very straightforward if you are comfortable using the command console.DirCmp Description:DirCmp is a straightforward command-line tool designed to help you compare two folders and identify files that are either missing or have been modified since the last backup. It is relatively easy to use, and it allows you to employ several filters to refine the scan.Winapp2kDirCmp is a useful command-line utility that can help you compare two folders and identify differences in content. It offers a decent feature set, and it. directory comparison with minimal output for huge collections - dircmp/dircmp at master bibermann/dircmp
6.7.1 The dircmp class - davis.lbl.gov
Anterior. (En caso de que los directorios # existan de una ejecución anterior se borrarán, # al principio, con todo su contenido).if os.path.exists("dir1"): shutil.rmtree("dir1")if os.path.exists("dir2"): shutil.rmtree("dir2")os.mkdir("dir1")os.mkdir("dir2")# En el directorio 'dir1' se copian los tres# archivos del ejemplo anterior. # Sin embargo, en el directorio 'dir2' se copia# el archivo 'arch1.txt' dos veces pero con # distinto nombre.shutil.copy2("arch1.txt", "dir1/arch1.txt")shutil.copy2("arch2.txt", "dir1/arch2.txt")shutil.copy2("arch3.txt", "dir1/arch3.txt")shutil.copy2("arch1.txt", "dir2/arch1.txt")shutil.copy2("arch1.txt", "dir2/arch2.txt")# Se declara una lista con una descripción breve# de la información que se va a obtener en la# comparación.tipos = ["iguales", "desiguales", "errores"]# Se declara una lista de nombres de archivos a# comparar en los dos directoriosarchivos = ["arch1.txt", "arch2.txt", "arch3.txt", "arch4.txt"]# Se realiza la búsqueda y comparación de los archivos # de la lista anterior en los dos directoriosresultado = filecmp.cmpfiles("dir1", "dir2", archivos, shallow=False)# Se imprime el resultado alcanzado (las tres listas:# 'iguales', 'desiguales' y 'errores').for t, r in zip(tipos, resultado): print(t, ":", r)'''Resultado---------iguales : ['arch1.txt']desiguales : ['arch2.txt']errores : ['arch3.txt', 'arch4.txt']'''# Observación:# En la lista de 'desiguales' aparece 'arch2.txt' porque# en 'dir1' se copia el archivo original y en 'dir2' # se copia 'arch1.txt' con el nombre 'arch2.txt'. # Cuando se comparan ambos directorios se detecta que # su contenido es diferenteLa clase dircmpLa clase dircmp permite crear nuevos objetos de comparación para comparar dos directorios (a y b).filecmp.dircmp(a, b, ignore=None, hide=None)El atributo ignore es una lista de nombres a ignorar. Por defecto tiene el valor de filecmp.DEFAULT_IGNORES. El atributo hide es una lista de nombres a ocultar. Por defecto tiene el valor del directorio actual "." (os.curdir) y del directorio padre ".." (os.pardir) Las comparaciones superficiales de archivos con la clase dircmp se realizan como con la función filecmp.cmp().Métodosreport(): Muestra por la salida estándar el resultado de la comparación entre dos directorios. report_partial_closure(): Muestra comparación parcial entre directorios a y b y subdirectorios comunes inmediatos.report_full_closure(): Muestra comparación parcial entre directorios a y b; y subdirectorios comunes (modo recursivo).Atributos de la clase dircmpSe emplea para acceder a variada información que se genera cuando se comparan dos árboles de directorios:left: el directorio a right: el directorio b left_list: contenido del directorio a (filtrado por ignore y hide) right_list:Message types used by DIRCMP.
. directory comparison with minimal output for huge collections - dircmp/dircmp at master bibermann/dircmpMessage types used by DirCMP.
Comments
Dircmp(1) General Commands Manual dircmp(1)Name dircmp - directory comparisonSyntax dircmp [ -d ] [ -s ] [ -wn ] dir...Description The command examines dir1 and dir2 and generates tabulated information about the contents of the directories. Listings of files that are unique to each directory are generated for all the options. If no option is entered, a list is output indicating whether the filenames common to both directories have the same contents. This command is supplied for X/OPEN compliance. The same results are available from which produces results more quickly and effectively.Options -d Compares the contents of files with the same name in both directories and output a list telling what must be changed in the two files to bring them into agreement. The list format is described in -s Suppresses messages about identical files. -wn Changes the width of the output line to n characters. The default width is 72.See Also cmp(1), diff(1). dircmp(1)
2025-04-1911.5.1 The dircmp class 11.5.1 The dircmp class dircmp instances are built using this constructor: class dircmp( a, b[, ignore[, hide]])Construct a new directory comparison object, to compare thedirectories a and b. ignore is a list of names toignore, and defaults to ['RCS', 'CVS', 'tags']. hide is alist of names to hide, and defaults to [os.curdir, os.pardir].The dircmp class provides the following methods:Print (to sys.stdout) a comparison between a and b. report_partial_closure( )Print a comparison between a and b and common immediatesubdirectories.Print a comparison between a and b and common subdirectories (recursively).The dircmp offers a number of interesting attributes that maybe used to get various bits of information about the directory treesbeing compared.Note that via __getattr__() hooks, all attributes arecomputed lazily, so there is no speed penalty if only thoseattributes which are lightweight to compute are used.left_listFiles and subdirectories in a, filtered by hide andignore.right_listFiles and subdirectories in b, filtered by hide andignore.commonFiles and subdirectories in both a and b.left_onlyFiles and subdirectories only in a.right_onlyFiles and subdirectories only in b.common_dirsSubdirectories in both a and b.common_filesFiles in both a and bcommon_funnyNames in both a and b, such that the type differs betweenthe directories, or names for which os.stat() reports anerror.same_filesFiles which are identical in both a and b.diff_filesFiles which are in both a and b, whose contents differ.funny_filesFiles which are in both a and b, but could not becompared.subdirsA dictionary mapping names in common_dirs todircmp objects.Release 2.5, documentation updated on 19th September, 2006.See About this document... for information on suggesting changes.
2025-04-01NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | USAGE | ENVIRONMENT VARIABLES | EXIT STATUS | ATTRIBUTES | SEE ALSONAMEdircmp- directory comparisonSYNOPSISdircmp [-ds] [-w n] dir1 dir2DESCRIPTIONThe dircmp command examines dir1and dir2 and generates various tabulated informationabout the contents of the directories. Listings of files that are uniqueto each directory are generated for all the options. If no option is entered,a list is output indicating whether the file names common to both directorieshave the same contents.OPTIONSThe following options are supported:-dCompares the contents of files with thesame name in both directories and output a list telling what must be changedin the two files to bring them into agreement. The list format is describedin diff(1).-sSuppressesmessages about identical files.-w nChanges the width of the output line to ncharacters. The default width is 72.OPERANDSThe following operands are supported:dir1dir2A path name of a directory to be compared.USAGESee largefile(5)for the description of the behavior of dircmp when encounteringfiles greater than or equal to 2 Gbyte ( 231bytes).ENVIRONMENT VARIABLESSee environ(5)for descriptions of the following environment variables that affect theexecution of dircmp: LC_COLLATE, LC_CTYPE, LC_MESSAGES, and NLSPATH.EXIT STATUSThe following exit values are returned:0Successful completion.>0An error occurred. (Differences in directory contents are not considerederrors.)ATTRIBUTESSee attributes(5)for descriptions of the following attributes: ATTRIBUTE TYPE ATTRIBUTE VALUE Availability SUNWesuSEE ALSOcmp(1), diff(1), attributes(5), environ(5), largefile(5)SunOS 5.9 Last Revised 1 Feb 1995NAME | SYNOPSIS | DESCRIPTION | OPTIONS | OPERANDS | USAGE | ENVIRONMENT VARIABLES | EXIT STATUS | ATTRIBUTES | SEE ALSO
2025-04-10源代码: Lib/filecmp.pyfilecmp 模块定义了用于比较文件及目录的函数,并且可以选取多种关于时间和准确性的折衷方案。对于文件的比较,另见 difflib 模块。filecmp 模块定义了如下函数:filecmp.cmp(f1, f2, shallow=True)¶比较名为 f1 和 f2 的文件,如果它们似乎相等则返回 True ,否则返回 False 。如果 shallow 为真,那么具有相同 os.stat() 签名的文件将会被认为是相等的。否则,将比较文件的内容。需要注意,没有外部程序被该函数调用,这赋予了该函数可移植性与效率。该函数会缓存过去的比较及其结果,且在文件的 os.stat() 信息变化后缓存条目失效。所有的缓存可以通过 clear_cache() 清除。filecmp.cmpfiles(dir1, dir2, common, shallow=True)¶比较在两个目录 dir1 和 dir2 中,由 common 所确定名称的文件。返回三组文件名列表: match, mismatch, errors 。 match 含有相匹配的文件, mismatch 含有那些不匹配的,然后 errors 列出那些未被比较文件的名称。如果文件不存在于两目录中的任一个,或者用户缺少读取它们的权限,又或者因为其他的一些原因而无法比较,那么这些文件将会被列在 errors 中。参数 shallow 具有同 filecmp.cmp() 一致的含义与默认值。例如, cmpfiles('a', 'b', ['c', 'd/e']) 将会比较 a/c 与 b/c 以及 a/d/e 与 b/d/e 。 'c' 和 'd/e' 将会各自出现在返回的三个列表里的某一个列表中。filecmp.clear_cache()¶清除 filecmp 缓存。如果一个文件过快地修改,以至于超过底层文件系统记录修改时间的精度,那么该函数可能有助于比较该类文件。3.4 新版功能.dircmp 类¶class filecmp.dircmp(a, b, ignore=None, hide=None)¶创建一个用于比较目录 a 和 b 的新的目录比较对象。 ignore 是需要忽略的文件名列表,且默认为 filecmp.DEFAULT_IGNORES 。 hide 是需要隐藏的文件名列表,且默认为 [os.curdir, os.pardir] 。dircmp 类如 filecmp.cmp() 中所描述的那样对文件进行 shallow 比较。dircmp 类提供以下方法:report()¶将 a 与 b 之间的比较打印(到 sys.stdout )。report_partial_closure()¶打印 a 与 b 及共同直接子目录的比较结果。report_full_closure()¶打印 a 与 b 及共同子目录比较结果(递归地)。dircmp 类提供了一些有趣的属性,用以得到关于参与比较的目录树的各种信息。需要注意,通过 __getattr__() 钩子,所有的属性将会惰性求值,因此如果只使用那些计算简便的属性,将不会有速度损失。left¶目录 a 。right¶目录 b 。left_list¶经 hide 和 ignore 过滤,目录 a 中的文件与子目录。right_list¶经 hide 和 ignore 过滤,目录 b 中的文件与子目录。common¶同时存在于目录 a 和 b 中的文件和子目录。left_only¶仅在目录 a 中的文件和子目录。right_only¶仅在目录 b 中的文件和子目录。common_dirs¶同时存在于目录 a 和 b 中的子目录。common_files¶同时存在于目录 a 和 b 中的文件。common_funny¶在目录 a 和 b 中类型不同的名字,或者那些 os.stat() 报告错误的名字。same_files¶在目录 a 和 b 中使用类的文件比较操作符相等的文件。diff_files¶在目录 a 和 b 中,根据类的文件比较操作符判定内容不等的文件。funny_files¶在目录 a 和 b 中无法比较的文件。subdirs¶一个将 common_dirs 中名称映射为 dircmp 对象的字典。filecmp.DEFAULT_IGNORES¶3.4 新版功能.默认被 dircmp 忽略的目录列表。下面是一个简单的例子,使用 subdirs 属性递归搜索两个目录以显示公共差异文件:>>> 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)
2025-04-21