Я изо всех сил пытался создать сценарий PowerShell v5, чтобы выполнить вышеизложенное, может быть, я усложняю все необходимое.
Имеет много zip-файлов, содержащих * docx-файлы и * ppm-файлы (я неМне не нужны файлы * ppm, поэтому я удаляю после распаковки).Временами * docx периодически обновляется, которые содержатся в папке Source.Мне нужен скрипт, который будет рекурсивно проходить через D: \ temp и предоставлять папку D: \ extract, которая содержит новые файлы из Source и сохраняет имена папок.(У меня работает распаковка, ниже "Разбитое" не работает)
123456-ABCD.zip
D:\temp\123456-ABCD\Doc1.docx
D:\temp\123456-ABCD\Doc2.docx
D:\temp\123456-ABCD\Doc3.docx
D:\temp\123456-ABCD\config.ppm
456789-EFGH.zip
D:\temp\456789-EFGH\Doc1.docx
D:\temp\456789-EFGH\Doc5.docx
D:\temp\456789-EFGH\config.ppm
Source:
D:\Working\_Source\Doc3.docx
D:\Working\_Source\Doc5.docx
End Result:
D:\extract\123456-ABCD\Doc3.docx (New from Source)
D:\extract\456789-EFGH\Doc5.docx (New from Source)
Вот что у меня так:
$ZipFilesPath = "D:\temp\"
$UnzipPath = "D:\out\"
$destination = "D:\extract\"
$diffdir = "D:\Working\_Source\"
## Unzips the files
Get-ChildItem -Filter *.zip -Recurse $ZipFilesPath | % { $_.FullName } | Split-Path | Get-Unique | % { cd $_ ; &'C:\Program Files\7-Zip\7z.exe' x *.zip -o* }
## Removes the PPM config files from unzip folders
Get-ChildItem -Path $ZipFilesPath *.ppm -Recurse | foreach { Remove-Item -Path $_.FullName }
## Moves the new folders skipping the zip files
Get-ChildItem -Path $ZipFilesPath -Recurse -Exclude "*.zip" | Move-Item -Destination $destination
### Broken
#Get the list of files in $destination
$oldfiles = Get-ChildItem -Recurse -path $destination| Where-Object {-not ($_.PSIsContainer)}
#get the list of files in new folder
$newfiles = Get-ChildItem -Recurse -path $UnzipPath | Where-Object {-not ($_.PSIsContainer)}
Compare-Object $oldfiles $newfiles -Property LastWriteTime -Passthru | sort LastWriteTime | foreach {
$fl = (($_.Fullname).ToString().Replace("$destination","$diffdir")).Replace("$UnzipPath","$diffdir")
$dir = Split-Path $fl
If (!(Test-Path $dir)){
mkdir $dir
}
copy-item $_.Fullname $fl
}