Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.scripting.vbscript > #12416

Re: EOL type detection

From "Mayayana" <mayayana@invalid.nospam>
Newsgroups microsoft.public.scripting.vbscript
Subject Re: EOL type detection
Date 2022-03-05 08:57 -0500
Organization A noiseless patient Spider
Message-ID <svvq9c$if$1@dont-email.me> (permalink)
References <bb79q57z2c92.16pyyy6q0tjfm.dlg@40tude.net>

Show all headers | View raw


"JJ" <jj4public@gmail.com> wrote

| The problem is that, there doesn't seem to be a way to retrieve the EOL 
type
| detected by FileSystemObject. In this case, we'd have to manually 
implement
| the EOL detection ourselves. Currently, I'm doing it like below, but IMO,
| it's a bit tedious. So, it there a simpler method.
|

  I take the opposite approach. Having different returns in
different files gets complicated. And some text file readers
don't recogize them. (My Notepad shows continuous text
with boxes to show line returns.)

  So I have a VBScript on my desktop.
If I download something like code samples using Unix line returns
I just drop the file or folder on my script. First the script checks
to see whether it's a file or folder, then it does the following:

Sub FixFol(FolPath)
 Dim SubPath, s2, sExt
     Set oFol = FSO.GetFolder(FolPath)
            Set oFils = oFol.Files
               For Each oFil in oFils
                   FPath = oFil.Path
                  sExt = UCase(Right(FPath, 3))
                 Select Case sExt
                   Case "TXT", ".MD", "TML", ".JS", "SON", "CSS", ".CS", 
"BAT", ".PY"
                       FixReturnsFile FPath
                       iCount = iCount + 1
                   Case Else
                      '--avoid touching binary files.
                  End Select
               Next
            Set oFils = Nothing

       Set Fols = oFol.SubFolders
         If Fols.count > 0 Then
             For Each Fol in Fols
                 SubPath = Fol.Path
                 FixFol SubPath
             Next
         End If
      Set Fols = Nothing
      Set oFol = Nothing
End Sub


Sub FixReturnsFile(sPath)
  On Error Resume Next
   Set TS = FSO.OpenTextFile(sPath, 1, False)
       s = TS.ReadAll
       TS.Close
   Set TS = Nothing

 '-------- replace linefeed characters with vbcrlf ------------------------
s1 = Replace(s, vbCrLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbLf, vbCr, 1, -1, 0)
s1 = Replace(s1, vbCr, vbCrLf, 1, -1, 0)
s1 = Replace(s1, vbCr & vbCr, vbCr, 1, -1, 0)

'-- -----write file. -----------------
If FSO.fileexists(sPath) = True Then
  FSO.deletefile sPath, True
End If
  Set TS = FSO.CreateTextFile(sPath, True)
     TS.Write s1
     TS.Close
  Set TS = Nothing
End Sub

Back to microsoft.public.scripting.vbscript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

EOL type detection JJ <jj4public@gmail.com> - 2022-03-05 15:39 +0700
  Re: EOL type detection "Mayayana" <mayayana@invalid.nospam> - 2022-03-05 08:57 -0500
    Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-06 06:27 +0700
  Re: EOL type detection "R.Wieser" <address@not.available> - 2022-03-05 15:49 +0100
    Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-06 06:28 +0700
      Re: EOL type detection "R.Wieser" <address@not.available> - 2022-03-06 10:06 +0100
        Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-08 05:36 +0700
          Re: EOL type detection "R.Wieser" <address@not.available> - 2022-03-08 11:03 +0100
            Re: EOL type detection JJ <jj4public@gmail.com> - 2022-03-09 09:30 +0700

csiph-web