Computing Staff
  • 7

Vbscript To Edit First Line Of All Text Files In Directory

  • 7

I’m trying to find a simple way to add a comma “,” to the first line a group of files. The files are created daily and need be edited once created.

Share

1 Answer

  1. Meh, I’m bored and it’s a slow Friday, so why not?

    Set fso = CreateObject("Scripting.FileSystemObject")
    For Each file In fso.GetFolder(".").Files
      If UCase(fso.GetExtensionName(file)) = "TXT" Then
        With file.OpenAsTextStream 
          txt = Array(.ReadLine, .ReadAll)
        End With
        file.OpenAsTextStream(2).Write Join(txt, "," & vbNewLine)
      End If
    Next 'file

    How To Ask Questions The Smart Way

    • 0