Jump to content
Sign in to follow this  
Reinhardt1julian

Overwrite line in file

Recommended Posts

Reinhardt1julian

I have a temp file, which stores necessary variables.  One of them is, how often a script was called. Now I'm searching for a way, how to increase the number in the file by one.

This is what I've already got:

$oldnum = FileReadLine($tempFileName, $line)
FileWriteLine($tempFileName, $oldnum + 1)

But FileWriteLine just adds a line at the bottom of the file. But I want to overwrite a given line (e.g. line number 7)

Thanks,

Reinhardt1Julian

Share this post


Link to post
Share on other sites
Melba23

Reinhardt1julian,

_FileWriteToLine is what you are looking for. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Starstar

$Filepathe ="D:\FolderEx1\FolderEx\Ex.txt"
_ReplaceStringInFile($Filepathe, "100", "10",1)

100 will be Replaced with 10 in a file.

Are you looking for that???

Edited by Starstar

Life is like a coin. You can spend it Anyway as you wish and for your kind information. "you can spend it only once."

Share this post


Link to post
Share on other sites
guinness

Starstar, answer was already provided.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Similar Content

    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have an inquiry from you
      I have a file path  with commands line
      Is there a way to separate the path from the commands line?
      I want the result in an array
      for example
      $path = '"c:\NVDA\NVDA slav Portable 1\NVDA.exe" -r -m -path="d:\NVDA Path\Portable"'
      there are any method to separate this text?
      i want the result to be as that
      $array[1] = "c:\NVDA\NVDA slav Portable 1\NVDA.exe"
      $array[2] = '-r -m -path="d:\NVDA Path\Portable"'
      Thanks in advance
      am Waiting for your answers
    • ur
      By ur
      In the autoit file, if we add multiple libraries (both internal and custom created one)
       
      When we compile the code and run the exe, some time we are getting runtime errors.
      But the line number of error is not showing the exact line number, might be it is including the line number count of libraries also.
      Can you please suggest how to get the exact error line number.
      So, it will be useful for debugging.
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an inquiry after your permission
      I found a function to get the special line commands for any operation
      It requires the name of the process to be searched
      I want to use it to know the process
      Is this possible with this function
      Here is the code
       
      Func commandLineGet($proc, $strComputer=".")
      dim $array[1]
      local $ArrayNumber
      local $oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
      local $oProcessColl = $oWMI.ExecQuery("Select * from Win32_Process where Name= " & '"'& $Proc & '"')
      local $Process
      For $Process In $oProcessColl
      $Process = $Process.Commandline
          ReDim $Array[UBound($Array)+1]
      $ArrayNumber = UBound($Array)-1
      $array[$ArrayNumber] = $Process
      Next
      $ArrayNumber = UBound($Array)-1
      $array[0] = $ArrayNumber
      return $array
      EndFunc
    • lewisg
      By lewisg
      Suddenly a RunWait command has stop working after 2 years of no errors, issues, or problems. The code uses RunWait to start Plink.exe, a command-line remote connection tool similar to UNIX ssh. I'm using it to ssh to a linux (Centos) machine, run a Perl script, and redirect the output to a file on a PC running the AutoIt script.  
       
      $FilePath = "C:\AutoIT\LED" $FilePathPlus = $FilePath & "\plink.exe" $Code1 = RunWait(@ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt ", @SW_SHOW) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " = ' & @ComSpec & " /c " & $FilePathPlus & " -ssh -l root -pw ?????? 10.170.4.163 /usr/local/nagios/etc/led.pl > C:\AutoIT\LED\led.txt " & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console The ConsoleWrite output when cut-n-pasted into a DOS box produces the expected file so I know it works. I've also tried many variations of the function moving, adding, and changing the " and ' (quote) marks. Also tried it without the @ComSpec macro and other related functions...e.g.  ShellExecuteWait , etc.
      The PC is a Windows 10 64bit and AutoIT is version 3.3.14.2.
      Searching here and Google has not yielded any clues that helped. 
×