Skip to content

Validate a list of files in PowerShell with Pester #2344

Answered by fflaten
erossini asked this question in Q&A
Discussion options

You must be logged in to vote
BeforeAll {
    function CheckFilesToDelete([string[]]$fList) {
        $fileList = [System.Collections.Generic.List[System.IO.FileInfo]]::new()

        foreach ($folderName in $fList) {
            $path = "$folderName"

            # Using -Filter for improved performance for filename filter
            # Convert to typed array so .AddRange() doesn't complain about object[] parameter
            $list = [System.IO.FileInfo[]]@(Get-ChildItem -Path $path -File -Recurse -Filter '*TMP*')
            if ($list.Count -gt 0) { $fileList.AddRange($list) }
        }

        return $fileList
    }
}

Describe 'Validate files to delete' {
    Context 'validate files' {
        It 'should return …

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@erossini
Comment options

@fflaten
Comment options

Answer selected by fflaten
@erossini
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@fflaten
Comment options

@erossini
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants