由于努力创建PowerShell v5脚本来完成上述任务,也许我使它变得更难了。
有许多包含* docx文件和* ppm文件的zip文件(我不需要* ppm文件,因此在解压缩后将其删除)。有时* docx会定期更新,这些时间都包含在Source文件夹中。我需要一个脚本,该脚本将递归地通过D:\ temp并提供D:\ extract文件夹,该文件夹包含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
}
这是我到目前为止所拥有的:
{{1}}