better handle missing MaxFileSize prop
This commit is contained in:
@@ -43,13 +43,14 @@ ForEach ( $plan in $BackupPlans ) {
|
|||||||
# Function to process each file
|
# Function to process each file
|
||||||
Function ProcessFile {
|
Function ProcessFile {
|
||||||
param([System.IO.FileInfo]$File)
|
param([System.IO.FileInfo]$File)
|
||||||
|
|
||||||
Switch ( $File ) {
|
Switch ( $File ) {
|
||||||
|
|
||||||
# Filter out if name matches an excluded path
|
# Filter out if name matches an excluded path
|
||||||
{ $null -ne ($ExcludedPaths | Where-Object { $File.FullName.Replace('\','\\') -match $_.Replace('\','\\') }) } { Update-FilteredFiles $File }
|
{ $null -ne ($ExcludedPaths | Where-Object { $File.FullName.Replace('\','\\') -match $_.Replace('\','\\') }) } { Update-FilteredFiles $File }
|
||||||
|
|
||||||
# Filter out if file size is greater than plan maximum
|
# Filter out if file size is greater than plan maximum
|
||||||
{ $File.Length -gt $plan.MaxFileSize } { Update-FilteredFiles $File }
|
{ $File.Length -gt $MaxFileSize } { Update-FilteredFiles $File }
|
||||||
|
|
||||||
# Add item to $IncludeFiles
|
# Add item to $IncludeFiles
|
||||||
default { $IncludedFiles.Add($item.FullName, $item.Length) | Out-Null }
|
default { $IncludedFiles.Add($item.FullName, $item.Length) | Out-Null }
|
||||||
@@ -110,6 +111,9 @@ ForEach ( $plan in $BackupPlans ) {
|
|||||||
ForEach ( $path in $IncludedPaths ) { Write-Output $path }
|
ForEach ( $path in $IncludedPaths ) { Write-Output $path }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Define $MaxFileSize if it exists, or set it to the max value of a long to bypass it
|
||||||
|
If ( $null -ne $plan.MaxFileSize ) { $MaxFileSize = $plan.MaxFileSize } Else { $MaxFileSize = [long]::MaxValue }
|
||||||
|
|
||||||
# Process each path in $IncludedPaths
|
# Process each path in $IncludedPaths
|
||||||
ForEach ($path in $IncludedPaths ) {
|
ForEach ($path in $IncludedPaths ) {
|
||||||
|
|
||||||
@@ -117,7 +121,7 @@ ForEach ( $plan in $BackupPlans ) {
|
|||||||
If ( !(Test-Path $path) ) { Continue }
|
If ( !(Test-Path $path) ) { Continue }
|
||||||
|
|
||||||
# If $path is an individual file, process it separately
|
# If $path is an individual file, process it separately
|
||||||
$item = Get-Item -Path $path
|
$item = Get-Item -Path $path -ErrorAction SilentlyContinue
|
||||||
If ( $item -is [System.IO.FileInfo] ) { ProcessFile $item ; Continue }
|
If ( $item -is [System.IO.FileInfo] ) { ProcessFile $item ; Continue }
|
||||||
|
|
||||||
# Get all children of $path
|
# Get all children of $path
|
||||||
|
|||||||
Reference in New Issue
Block a user