samedi 7 juillet 2018

Struggnling with loops and conditions

I am quering SQLSERVER from powershell script and return a value that I store in variable as $latestVersion.

I have a folder with 30 files having same static name at the beginning but ends with different day:

TEMP.file
TEMP 20181010.file
TEMP 20181011.file
TEMP 20181012.file
...

What I am struggling with is the following:

if $latestVersion is only TEMP, I'd like to execute files from 25 to 30 for the purpose I am using an if statement to check

if $latestVersion points to say the 27th file I'd like to execute what's greater than that so -> 28-29-30

if $latestVersion equals the latest file ECHO I'm ok

my problem comes from not knowing how to elegantly chuck away TEMP.file as in comparisons he is the greater one of them all.

so having a foreach loop

foreach ($file in $fileList)
{
   if(($latestVersion -ne TEMP.file) -and ($file -gt $file15))

   $toExecute = $file

   foreach ($exec in $toExecute)
   {
       run $exec
   }
}

the problem is TEMP.file is always greater and do not know how to work around it

Aucun commentaire:

Enregistrer un commentaire