Page 1 of 1

add suffix to the end of every line of every text file

Posted: 16 Sep 2018, 09:36
by way2000
i need a script that can add a suffix to every line of every text file in a folder

does anyone have an example i can work with?

please help if possible

Re: add suffix to the end of every line of every text file

Posted: 16 Sep 2018, 10:12
by garry
example
( instead delete original file can also write to a new file )

Code: Select all

;- reads textfiles and add  "_ADD" at end of line
setworkingdir,%a_scriptdir%
Extensions:= "txt,bas,bat"      ;- some extensions
PRESELECT  =%a_desktop%         ;- search from here

FileSelectFolder,MF,%PRESELECT%
if MF=
  return
setworkingdir,%MF%
Loop, %mf%\*.*, 0, 1
  {
  If A_LoopFileExt in %Extensions%
   {
   e=
   y:=A_LoopFileFullPath
    FileRead,aa,%y%
	  Loop, parse,aa, `n, `r
      {
	  x := a_loopfield
      if (x="")
	    continue
	  e .= x . "_ADD`r`n"
      }
   ;Filedelete,%y%	     ;- instead delete can also write to a new file
   ;Fileappend,%e%,%y%
   new=%dir%\%name_no_ext%_NEW.%ext%
   ;msgbox,%new%
   Fileappend,%e%,%new%
   e=   
   }
 }
run,%mf% 
return

Re: add suffix to the end of every line of every text file

Posted: 28 Sep 2018, 02:07
by Guest
For reference, TF has a such a function also to do so in specific lines, https://github.com/hi5/TF#TF_InsertSuffix