$source = "C:\Users\User\Videos\4K Video Downloader" # Startordner $destination = "H:" # zielordner. $logFile = "F:\sync-log.txt" # Protokollverzeichnis ( muss immer \sync-log.txt sein das ist der name der datei. $intervall = 30 * 60 # 30 Minuten $categories = @{ "Bilder" = @("jpg","jpeg","png","gif","bmp","webp","tiff") "Videos" = @("mp4","mkv","avi","mov","wmv","flv") "Audio" = @("mp3","wav","flac","aac","m4a","ogg") "Dokumente" = @("pdf","doc","docx","xls","xlsx","ppt","pptx","txt","odt") "Archive" = @("zip","rar","7z","tar","gz") "Programme" = @("exe","msi","bat") "Sonstiges" = @() } function Get-Category($ext) { foreach ($cat in $categories.Keys) { if ($categories[$cat] -contains $ext) { return $cat } } return "Sonstiges" } while ($true) { try { Write-Host "$(Get-Date -Format 'HH:mm:ss') - Starte Kopieren und Sortieren..." $allFiles = Get-ChildItem -Path $source -File -Recurse foreach ($file in $allFiles) { $ext = $file.Extension.TrimStart('.').ToLower() if ([string]::IsNullOrEmpty($ext)) { $ext = "Sonstiges" } $category = Get-Category $ext $targetFolder = Join-Path -Path $destination -ChildPath $category if (-not (Test-Path $targetFolder)) { New-Item -Path $targetFolder -ItemType Directory | Out-Null } $targetFile = Join-Path $targetFolder $file.Name try { # Kopieren nur, wenn die Datei nicht existiert oder sich geändert hat if (-not (Test-Path $targetFile) -or ($file.LastWriteTime -gt (Get-Item $targetFile).LastWriteTime)) { Copy-Item -Path $file.FullName -Destination $targetFile -Force Add-Content -Path $logFile -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Kopiert: $($file.FullName) -> $targetFile" } } catch { Add-Content -Path $logFile -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Fehler beim Kopieren: $($file.FullName) - $_" } } Write-Host "$(Get-Date -Format 'HH:mm:ss') - Vorgang abgeschlossen." } catch { Add-Content -Path $logFile -Value "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - Allgemeiner Fehler: $_" } Write-Host "$(Get-Date -Format 'HH:mm:ss') - Warte $($intervall/60) Minuten bis zum nächsten Durchlauf..." Start-Sleep -Seconds $intervall }