Ответ на пост «Полезные команды Linux»
# ... (previous code)
# Get user input for source directory
$sourceDirectory = Read-Host "Enter the source directory:"
# ... (other input prompts)
# Get files to archive
$filesToArchive = Get-ChildItem -Path $sourceDirectory -Filter $fileExtension
# ... (rest of the code)
# Check for archive creation errors
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create archive. Error code: $LASTEXITCODE"
# You could add specific error handling based on the error code
}
# ... (rest of the code)
# Check for file deletion errors
foreach ($file in $filesToArchive) {
try {
Remove-Item -Path $file.FullName -Force
} catch {
Write-Error "Failed to delete file: $($_.Exception.Message)"
}
}