Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>first, it seems <code>set</code> does not like spaces between the variable and the <code>=</code> sign: if you put a space, the variable name will include a space. so you must remove the space to properly define the variable name. </p> <p>plus, your syntax for capturing the output of the command into a variable is wrong. the only way i am aware of (after desperately searching stackoverflow for the answer) is to use a for loop trick to use a temporary variable (see <a href="https://stackoverflow.com/questions/108439/how-do-i-get-the-result-of-a-command-in-a-variable-in-windows">this question</a> for more details). actually, you also need to escape the pipe for the command to be parsed correctly.</p> <p>then, when the variable tested in the <code>if</code> expression does not exists, the results is always true, so make sure the variable exists. by removing the space as said above, the name in the if expression will match your variable name, and the test will execute properly.</p> <p>then you forgot to make a block around the 2 last commands. actually, you are testing if you have more than 21 files and compute the oldest if it is true, then you ALWAYS delete the oldest.</p> <p>also, the greater than operator <code>&gt;</code> may be understood as a redirection. you may need to use the GTR operator. </p> <pre><code>SET BACKUPDIR=C:\test FOR /F %%i in ('dir BACKUPDIR /b ^| find /v /c "::"') DO SET countfiles=%%i if countfiles GTR 21 ( FOR /F %%i IN ('DIR /B /O-D %BACKUPDIR%') DO SET OLDEST=%%i DEL %BACKUPDIR%\%OLDEST% ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload