# --- USTAWIENIA --- $ListaPlikow = '\\192.168.0.10\photo.abisal.pl\_ARCHIWUM_\WSAD.txt' # ścieżki plików, po jednej w linii $Root = '\\192.168.0.10\photo.abisal.pl' $ArchiveRoot = '\\192.168.0.10\photo.abisal.pl\_ARCHIWUM_' $LogFile = '\\192.168.0.10\photo.abisal.pl\_ARCHIWUM_\archiwum_log.txt' # --- START --- New-Item -Path $ArchiveRoot -ItemType Directory -Force | Out-Null $ok = 0; $err = 0 $sw = [System.Diagnostics.Stopwatch]::StartNew() "START $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')" | Out-File -FilePath $LogFile -Encoding UTF8 Get-Content -LiteralPath $ListaPlikow | ForEach-Object { $src = $_.Trim() if ([string]::IsNullOrWhiteSpace($src)) { return } try { if (-not (Test-Path -LiteralPath $src -PathType Leaf)) { $err++; "MISSING | $src" | Out-File -FilePath $LogFile -Append -Encoding UTF8 return } # weryfikacja, że ścieżka zaczyna się od ROOT if ($src -notlike "$Root*") { $err++; "OUTSIDE_ROOT | $src" | Out-File -FilePath $LogFile -Append -Encoding UTF8 return } # relatywna część względem ROOT: \Skating\Akcesoria\hamulce\plik.jpg $relative = $src.Substring($Root.Length).TrimStart('\') # rozbij na foldery i nazwę pliku $leaf = Split-Path -Path $src -Leaf $relDir = [System.IO.Path]::GetDirectoryName($relative) # Skating\Akcesoria\hamulce $dstDir = if ([string]::IsNullOrEmpty($relDir)) { $ArchiveRoot } else { Join-Path $ArchiveRoot $relDir } $dstPath = Join-Path $dstDir $leaf # utwórz katalog docelowy, jeśli go nie ma New-Item -Path $dstDir -ItemType Directory -Force | Out-Null # PRZENIEŚ plik (usuń -WhatIf, by wykonać naprawdę) Move-Item -LiteralPath $src -Destination $dstPath -Force #-WhatIf $ok++; "MOVED | $src -> $dstPath" | Out-File -FilePath $LogFile -Append -Encoding UTF8 } catch { $err++; "ERROR | $src | $($_.Exception.Message)" | Out-File -FilePath $LogFile -Append -Encoding UTF8 } } $sw.Stop() "DONE | OK=$ok | ERR=$err | Time=$($sw.Elapsed)" | Out-File -FilePath $LogFile -Append -Encoding UTF8 Write-Host "Zakończono. OK=$ok, ERR=$err. Log: $LogFile"