VFile creator

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Aacini
Expert
Posts: 1913
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: VFile creator

#16 Post by Aacini » 21 Jan 2022 09:22

aGerman wrote:
21 Jan 2022 03:29
Antonio,
I guess this is going to turn the LFs in the BODY into CR LFs, right?

Steffen

Ops! You are right! :?

This is the fixed code:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set ^"LF=^
%empty line%
^"

set /A "lastOffset=0, i=0"
for /F "delims=:" %%a in ('findstr /O "^" test.txt') do (
   set /A "len[!i!]=%%a-lastOffset-2, lastOffset=%%a, i+=1"
)
for %%a in (test.txt) do set /A "len[%i%]=%%~Za-lastOffset-1"

set "i=0"
set "inBody="

>"T1.txt" <NUL (for /F "delims=" %%a in (test.txt) do (

   set "line=%%a"
   set /A i+=1
   set /A "len=len[!i!]"
   for %%i in (!len!) do set "endsInLF=!line:~%%i!"

   if not defined inBody (

      for /F "tokens=1-3 delims=;" %%i in ("%%a") do (
         echo BEGIN:VMESSAGE
         echo TYP:SMS;IN
         echo BOX:INBOX
         echo READ:0
         echo DATE:%%j
         echo NUMBER:%%i
         if not defined endsInLF (
            echo BODY;CHARSET=1253:%%k
            echo END:VMESSAGE
         ) else (
            set /P "=BODY;CHARSET=1253:%%k!LF!"
            set "inBody=1"
         )
      )

   ) else (

      if defined endsInLF (
         set /P "=%%a!LF!"
      ) else (
         echo %%a
         echo END:VMESSAGE
         set "inBody="
      )
   )

))
Antonio

Post Reply