Powershell: si el ARCHIVO (comodín) existe y tiene más de 0 kb

Powershell: si el ARCHIVO (comodín) existe y tiene más de 0 kb

Puedo verificar con éxito si existe un archivo y tiene más de 0 kb usando lo siguiente:

$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
}

Puedo comprobar si existe un archivo comodín usando lo siguiente:

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

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

Sin embargo, no puedo lograr que los dos conceptos funcionen juntos. A continuación, si el archivo comodín existe; el retorno es siempre 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
}

Respuesta1

Ok, jugando un poco más y se me ocurrió algo que funciona:

$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
}

Si alguien tiene una solución más limpia, todavía me encantaría verla.

EDITAR: Cambié bastante mi solución. Nuevamente, si hay una mejor manera de hacer esto; Estoy muy abierto a sugerencias que me ayudarán a mejorar mis conocimientos y habilidades generales.

información relacionada