如何在Windows Powershell中区分两个文件夹?

我试图找到使用 Windows Powershell的两个文件夹结构的内容的差异.我使用以下方法来确保文件名相同,但此方法不会告诉我文件内容是否相同:
$firstFolder = Get-ChildItem -Recurse folder1
$secondFolder = Get-ChildItem -Recurse folder2
Compare-Object -ReferenceObject $firstFolder -DifferenceObject $secondFolder

this ServerFault question中描述的技术适用于区分单个文件,但这些文件夹包含数百个不同深度的文件.

解决方案不一定需要告诉我文件中的具体内容是什么 – 只是它们是.我对日期等元数据的差异不感兴趣,我已经知道它与众不同.

如果你想将比较包装成循环,我会采取以下方法
$folder1 = "C:\Users\jscott"
$folder2 = "C:\Users\public"

# Get all files under $folder1,filter out directories
$firstFolder = Get-ChildItem -Recurse $folder1 | Where-Object { -not $_.PsIsContainer }

$firstFolder | ForEach-Object {

    # Check if the file,from $folder1,exists with the same path under $folder2
    If ( Test-Path ( $_.FullName.Replace($folder1,$folder2) ) ) {

        # Compare the contents of the two files...
        If ( Compare-Object (Get-Content $_.FullName) (Get-Content $_.FullName.Replace($folder1,$folder2) ) ) {

            # List the paths of the files containing diffs
            $_.FullName
            $_.FullName.Replace($folder1,$folder2)

        }
    }   
}

请注意,这将忽略$folder1和$folder2中不存在的文件.

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...