这就是我所拥有的:
import filecmp
from filecmp import dircmp
def print_right_only(dcmp):
for name in dcmp.right_only:
print "%s not found in %s but found in %s" % (name, dcmp.left,
dcmp.right)
for sub_dcmp in dcmp.subdirs.values():
print_right_only(sub_dcmp)
dcmp = dircmp('E:\GIS', 'J:\GIS')
print_right_only(dcmp)
这完全符合要求。我希望能够从结果中过滤或排除* .lock文件。我确实看到了一个与dircmp相关的忽略函数但无法让它返回任何结果。我是python的一个非常基本的用户。
答案 0 :(得分:1)
Func<dynamic, dynamic> DynamicProperty(Func<dynamic, dynamic> selector)
{
return x =>
{
try
{
return selector(x);
}
catch (RuntimeBinderException)
{
return null;
}
};
}
&#39; var sorted = list
.OrderBy(DynamicProperty(x => x.property1))
.ThenBy(DynamicProperty(x => x.property2));
并不接受整个文字。
通过将dircomp
替换为:
ignore
在致电filecmp._filter
之前执行此操作,然后from fnmatch import fnmatch
def _filter(flist, skip):
return [item for item in flist
if not any(fnmatch(item, pat) for pat in skip)]
filecmp._filter = _filter
将按预期工作。
未测试。
答案 1 :(得分:0)
事后可以进行过滤吗?
import filecmp
from filecmp import dircmp
def print_right_only(dcmp):
for name in dcmp.right_only:
if name.endswith('.lock'): # Check if it is a lock file.
continue
print "%s not found in %s but found in %s" % (name, dcmp.left,
dcmp.right)
for sub_dcmp in dcmp.subdirs.values():
print_right_only(sub_dcmp)
dcmp = dircmp('E:\GIS', 'J:\GIS')
print_right_only(dcmp)