From 07b9dd929ee86ce280f27f837e4ddf9934996300 Mon Sep 17 00:00:00 2001 From: Adam Rudell Date: Mon, 28 Oct 2024 02:21:55 -0500 Subject: [PATCH] Skip creating empty file (#333) # Description Summary of changes: - Exit the function if the arrayList is empty. # Change type - [x] Bug fix (non-breaking change) - [ ] Code style update (formatting, local variables) - [ ] New Feature (non-breaking change that adds new functionality without impacting existing) - [ ] Breaking change (fix or feature that may cause functionality impact) - [ ] Other # Checklist: - [x] My code follows the style and contribution guidelines of this project. - [x] I have tested and validated my code changes. --- .../SdnDiag.Utilities/private/Export-ObjectToFile.ps1 | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/modules/SdnDiag.Utilities/private/Export-ObjectToFile.ps1 b/src/modules/SdnDiag.Utilities/private/Export-ObjectToFile.ps1 index e953c8e..7e151c9 100644 --- a/src/modules/SdnDiag.Utilities/private/Export-ObjectToFile.ps1 +++ b/src/modules/SdnDiag.Utilities/private/Export-ObjectToFile.ps1 @@ -43,9 +43,7 @@ function Export-ObjectToFile { # create the parent directory structure if does not already exist if(!(Test-Path -Path $fileName.Directory -PathType Container)){ - try { - "Creating directory {0}" -f $fileName.Directory | Trace-Output -Level:Verbose $null = New-Item -Path $fileName.Directory -ItemType Directory -ErrorAction Stop } catch { @@ -55,14 +53,13 @@ function Export-ObjectToFile { } } process { - # if object is null, then exit - if ($null -eq $Object) { - return - } - $arrayList.AddRange($Object) } end { + if ($arrayList.Count -eq 0) { + return + } + try { "Creating file {0}" -f $fileName | Trace-Output -Level:Verbose switch($FileType){