Jump to content

fileWrite probelm


JAVAAA

Recommended Posts

Hey, I am asking how to write a new string before the original string that is existed in the file. Example:

txt file contains "100" then I want to write a string before "100"

My Code:

function addUpdate(content)
	local file = "UpdatesLog.txt"
	local openFile = fileOpen(file)
	if not openFile then outputChatBox("Error loading file") return false end
	local date, time = getTimeDate()
		fileSetPos(openFile, fileGetPos(openFile))
		if (fileGetSize(openFile) == 0) then
			fileWrite(openFile, "["..date.."]", content)
		else
			fileSetPos(openFile, fileGetSize(openFile))
			fileWrite(openFile, "\r\n["..date.."]", content)
		end
	outputChatBox("#D16C00NEW UPDATES GOT ADDED!", getRootElement(), 255, 255, 255, true)
	outputChatBox("#D16C00-  "..content, getRootElement(), 255, 255, 255, true)
	fileClose(openFile)
end
addEvent("COKupdates.addUpdate", true)
addEventHandler("COKupdates.addUpdate", root, addUpdate)

Now it writes a string after the original one.

Edited by JAVAAA
Link to comment

Is there a specific position you will want to insert the new text or always before the old text, like

[old_line1][old_line2] [ NEW LINE ] [old_line3] -> specific

Or always before everything else?

[NEW LINE][old_line1][old_line2] -> always there

Link to comment
16 minutes ago, pa3ck said:

Is there a specific position you will want to insert the new text or always before the old text, like

[old_line1][old_line2] [ NEW LINE ] [old_line3] -> specific

Or always before everything else?

[NEW LINE][old_line1][old_line2] -> always there

 

Before everything

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...