PowerShell 将较新的文件镜像到另一个文件中
我需要一些有关 PowerShell 的帮助,我尝试了几个小时,但我不明白它是如何工作的。 (代码中的文本是德语,只需忽略它)对于该程序,我基本上想在镜像文件时执行此操作,每个文件夹中的较新文件都会被镜像。例如,我有 2 个文件夹:temp 和 temp2。 temp example.txt 中有一个于中午 12:00 创建的文件,temp2 中有一个于下午 2:00 创建的同名文件。我想镜像较新的文件,即使它位于目标文件夹中,如果目标文件夹中的文件较新,我也想将其镜像到源文件夹中。
我希望这个解释是可以理解的,并且有人可以提供帮助。我试图自己解决这个问题,但我没有成功。我很高兴得到答案
write-host "Bitte geben Sie den Sourcepath ein, nur Ordner. Am ende des zielordners Ordners KEIN backslash"
$source = Read-Host
write-host "Bitte geben Sie den Destinationpath ein. Am ende des zielordners Ordners KEIN backslash"
$destination = Read-Host
while($True){
write-host "Wollen sie irgendwelche Dateiendungen NICHT rüber kopieren? j=ja, n=nein"
$choice0 = read-host
if($choice0 -eq "j"){
write-host "Welche dateiendung?"
$fileendInput = read-host
$fileending = "*." + $fileendInput
break
}
elseif($choice0 -eq "n"){
break
}
else{
write-host "Ungültige eingabe, nochmal probieren."
}
}
$Exclude = @($fileending)
Get-ChildItem $source -Recurse | ForEach {
$ModifiedDestination = $($_.FullName).Replace("$source","$destination")
If ((Test-Path $ModifiedDestination) -eq $False) {
Copy-Item $_.FullName $ModifiedDestination -Exclude $Exclude
}
}
Remove-Variable fileendInput
Remove-Variable fileending
Remove-Variable Exclude
I need some help with PowerShell, I tried for hours but I couldn't figure out how that works. (The Text in the code is German, just ignore that) For the Program I basically wanted to do that when you mirror the files, that the newer file in each folder gets mirrored. So for example I have 2 folders: temp and temp2. There's a file in temp example.txt created at 12:00 PM and there's a file in temp2 with the same name created at 2:00PM. I want to mirror the newer file, even if it is in the destination folder, i want to mirror it into the source folder if the file in the destination folder is newer.
I hope that this explanation is kinda understandable, and that someone can help with that. I tried to figure it out myself but I didn't make it. I'd be really happy for an answer
write-host "Bitte geben Sie den Sourcepath ein, nur Ordner. Am ende des zielordners Ordners KEIN backslash"
$source = Read-Host
write-host "Bitte geben Sie den Destinationpath ein. Am ende des zielordners Ordners KEIN backslash"
$destination = Read-Host
while($True){
write-host "Wollen sie irgendwelche Dateiendungen NICHT rüber kopieren? j=ja, n=nein"
$choice0 = read-host
if($choice0 -eq "j"){
write-host "Welche dateiendung?"
$fileendInput = read-host
$fileending = "*." + $fileendInput
break
}
elseif($choice0 -eq "n"){
break
}
else{
write-host "Ungültige eingabe, nochmal probieren."
}
}
$Exclude = @($fileending)
Get-ChildItem $source -Recurse | ForEach {
$ModifiedDestination = $($_.FullName).Replace("$source","$destination")
If ((Test-Path $ModifiedDestination) -eq $False) {
Copy-Item $_.FullName $ModifiedDestination -Exclude $Exclude
}
}
Remove-Variable fileendInput
Remove-Variable fileending
Remove-Variable Exclude
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论