Powershell - Se FILE (curinga) existir e for maior que 0kb

Powershell - Se FILE (curinga) existir e for maior que 0kb

Posso verificar com êxito se um arquivo existe e é maior que 0kb usando o seguinte:

$getFILE = 'C:\DIR\FILE1.txt'

IF (test-path $getFILE){
    IF ((get-item $getFILE).length -gt 0) {
        "OK";return 0
    }
    ELSE {
        "0 bytes";return 2
    }
}
ELSE {
    "doesn't exist";return 1
}

Posso verificar se existe um arquivo curinga usando o seguinte:

$getFILE = 'C:\DIR\FILE*.*'

IF (test-path $getFILE){
    "OK";return 0
}
else {
    "doesn't exist";return 1
}

Não consigo fazer com que os dois conceitos funcionem juntos. A seguir, se o arquivo curinga existir; o retorno é sempre 0:

$getFILE = 'C:\DIR\FILE*.*'

IF (test-path $getFILE){
    IF ((get-item $getFILE).length -gt 0) {
        "OK";return 0
    }
    else {
        "0 bytes";return 2
    }
}
else {
    "doesn't exist";return 1
}

Responder1

Ok, mais um pouco de brincadeira e descobri algo que está funcionando:

$vDIR = 'C:\DIR'
$vFILE = 'FILE*.*'

$proc = @(Get-ChildItem $vDIR -Recurse -Include $vFile | Where {$_.length -gt 0})
If ($proc.count -gt 0) {
   ForEach ($item in $proc) {
      Do a bunch of stuff
   }
Else {
   Do this other thing
}

Se alguém tiver uma solução mais limpa, eu ainda adoraria vê-la.

EDIT: Mudei um pouco minha solução. Novamente, se houver uma maneira melhor de fazer isso; Estou super aberto a sugestões que me ajudarão a melhorar meus conhecimentos/habilidades gerais.

informação relacionada