我有两个不同的文件夹(旧的和新的),包含子文件夹和.xml文件。我需要知道相对于旧文件夹在新文件夹中添加或删除(未编辑!)的文件。如何使用PowerShell执行此操作?
答案 0 :(得分:0)
最简单的一个(将以递归方式查找文件夹中的所有XML文件):
$folder1 = ""
$folder2 = ""
$fol1 = Get-ChildItem -Recurse $folder1 -Filter *.xml| select name, directory, CreationTime
$fol2 = Get-ChildItem -Recurse $folder2 -Filter *.xml| select name, directory, CreationTime
Compare-Object $fol1 $fol2 -Property name -PassThru | select name, CreationTime, @{
N = "Folder"; e= {
if ($_.sideindicator -eq "=>") { "Not Found in $folder2" }
elseif ($_.sideindicator -eq "<=") { "Not Found in $folder1" }
}
}
输出:
Name CreationTime Folder
---- ------------ ------
New Text Document.txt 7/5/2017 1:24:35 PM Not Found in G:\xxx
1.exe 6/14/2017 3:17:29 PM Not Found in G:\111
1.dll 6/14/2017 3:17:37 PM Not Found in G:\1