如何在Windows Powershell中区分两个文件夹?
发布时间:2021-01-23 16:33:50 所属栏目:Windows 来源:网络整理
导读:我试图找到使用 Windows Powershell的两个文件夹结构的内容的差异.我使用以下方法来确保文件名相同,但此方法不会告诉我文件的内容是否相同: $firstFolder = Get-ChildItem -Recurse folder1$secondFolder = Get-ChildItem -Recurse folder2Compare-Object -
我试图找到使用 Windows Powershell的两个文件夹结构的内容的差异.我使用以下方法来确保文件名相同,但此方法不会告诉我文件的内容是否相同: $firstFolder = Get-ChildItem -Recurse folder1 $secondFolder = Get-ChildItem -Recurse folder2 Compare-Object -ReferenceObject $firstFolder -DifferenceObject $secondFolder this ServerFault question中描述的技术适用于区分单个文件,但这些文件夹包含数百个不同深度的文件. 解决方案不一定需要告诉我文件中的具体内容是什么 – 只是它们是.我对日期等元数据的差异不感兴趣,我已经知道它与众不同. 如果你想将比较包装成循环,我会采取以下方法:$folder1 = "C:Usersjscott" $folder2 = "C:Userspublic" # 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中不存在的文件. (编辑:站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-server-2008 – 软件与硬件RAID1(镜像)
- PC和Android合体 微软宣布Windows 11安卓子系统下月全面开放
- win10任务栏不显示打开的应用怎么处理
- 如何在VMware虚拟机上安装Windows 11,即使它不符合系统需求
- Windows10系统下获取文件路径的办法
- windows – 我真的需要MS Active Directory吗?
- windows-server-2012 – 识别Windows 2012 Server核心
- win10定时关机设定方法
- 是否可以远程关闭Windows上的远程桌面会话?
- Windows Server 2012 R2本身是否支持IIS SFTP?
站长推荐
热点阅读