Solved vbscript to edit first line of all text files in directory

August 24, 2012 at 09:38:20
Specs: Windows 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.

See More: vbscript to edit first line of all text files in directory

Report •


#1
August 24, 2012 at 13:27:38
✔ Best Answer
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


Report •

#2
August 24, 2012 at 14:24:14
Today is my lucky day! This will save a ton of time, over, and over, and over... I really appreciate the help!

Report •

#3
August 25, 2012 at 03:37:07
:: ===== script starts here ===============
::
:: patrick.bat 2012-08-25 16:01:30.37
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in ('dir/b *.txt') do (
set F=%%a
call :sub1 !F!
)
goto :eof

:sub1
set N=
for /f "tokens=* delims= " %%i in (!F!) do (
set /a N+=1
if !N! equ 1 (
echo.%%i,
) else (
echo.%%i
)
)>> newfile
move /y newfile !F!
goto :eof
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions


Ask Question