@Echo Off
SetLocal EnableExtensions EnableDelayedExpansion

Title Сжатие файлов
Set ErrFlag=

For /F "Delims=" %%I In (Temp\Folders.txt) Do (
  If Not Exist "%%I\Files\Compressed" MD "%%I\Files\Compressed"

  For %%K In ("%%I\Files\*.*") Do (
    Set V=%%~xK
    If "!V!"=="" Set V=.
    Set V=!V:~0,3!_

    If Exist "%~1\%%~nK!V!" (
      Echo %%~nxK
      If Not Exist "%%I\Files\Compressed\%%~nK!V!" (
        MakeCab /D CompressionMemory=21 /D CompressionType=LZX /L "%%I\Files\Compressed" "%%K" >nul

        If Not Exist "%%I\Files\Compressed\%%~nK!V!" (
          Echo Ошибка при сжатии %%~nxK.
          Set ErrFlag=1
        )
      )
    )
  )
)

If "!ErrFlag!"=="1" Pause & Exit 1
Exit 0
