一个简单的起点: compare (dir -r dir1) (dir -r dir2) -Property name,length,lastwritetime您还可以添加-passthru来查看原始对象,或者添加-includeequal来查看相同的元素。没有-syncwindow,每个数组的顺序都不重要。我假设所有的最后写时间都是同步的,到毫秒。不要假设您可以跳过指定要比较的属性。另见将文件夹和内容与PowerShell进行比较 我在研究计算出的属性,比如相对路径,但看起来你无法命名它们,即使在powershell 7中。我正在砍掉前四个路径元素0..3。 compare (dir -r foo1) (dir -r foo2) -Property length,lastwritetime,@{e={($_.fullname -split '\\')[4..$_.fullname.length] -join '\'}}
length lastwritetime ($_.fullname -split '\\')[4..$_.fullname.length] -join '\' SideIndicator
------ ------------- ---------------------------------------------------------- -------------
16 11/12/2022 11:30:20 AM foo2\file2 =>
18 11/12/2022 11:30:20 AM foo1\file2 |