|Fred Zanella (fredzaza2)||20.05.2015 22:16|
|hi , i want to add a line in a file without erasing the first part of this file.When i use " io.open (filename, "w")" the first part is deleted . it is posible to add line in back or middle of a file ?
|Emil Drefers (Unknown)||21.05.2015 08:00|
no, you can only write to a file by erasing its content first.
But you could try to read the content of the file before writing to it ;)
|Fred Zanella (fredzaza2)||21.05.2015 19:08|
|so , i can use a function for reading the first part , save and rewrite my new line and the first part ?
|Emil Drefers (Unknown)||22.05.2015 07:27|
local file = io.open(filename, "r");
you should be able to open a file for rading its content.
What you do with the information in the file afterwards is up to you ;)
|Fred Zanella (fredzaza2)||22.05.2015 17:26|
|ok , thank you for your help
|Karl Schneeberger (Unknown)||26.07.2015 20:47|
did that work?
If i try to do that, I get always a warning "Warning: io.open, only write mode ('w') is allowed"
and the file is not opened.
Part of my code:
if fileExists(newFileName) and fileExists(oldFileName) then
oldFile = io.open(oldFileName, "r");
What's wrong with my code?
|Emil Drefers (Unknown)||27.07.2015 07:55|
that's correct io.open only works in the "w" mode.
But there's an other way to read the contents of an xml file.
e.g. line 14 in:
|Karl Schneeberger (Unknown)||27.07.2015 13:53|
you mean line 24?
??local xmlFile = loadXMLFile("TempXML", xmlFilename); ??
My problem is, that i would like to access "inputbindings.xml"
Unfortunately, all the entries have the same secondLevel.id (input or axis).
So, i can not access a specific line by the ..XML.. functions.
|Emil Drefers (Unknown)||27.07.2015 14:40|
ups, yes I meant line 24.
Well, you could search for the desired line by checking the "name" attribute. (?)
|Karl Schneeberger (Unknown)||27.07.2015 15:22|
i tried the following:
xmlFile = loadXMLFile("input_XML", fileName, "gamePadOrder");
local res = getXMLString(id, "inputBinding.input#name");
Yes, that works for the first entry.
But how do i get all the others? They all start with the same XMLPath...
|Emil Drefers (Unknown)||28.07.2015 08:12|
well, you could have had a look at the scripts in the script documentation to understand how you can access such elements.
first element: getXMLString(id, "inputBinding.input(0)#name");
second element: getXMLString(id, "inputBinding.input(1)#name");
third element: getXMLString(id, "inputBinding.input(2)#name");
so on and so forth ...
in a loop you could do something like:
getXMLString(id, string.format("inputBinding.input(%d)#name", i));
|Karl Schneeberger (Unknown)||28.07.2015 16:24|
that was the needed information to solve my problem.
Thanks a lot, you made my day.
- Collect all the scripting information on one page.
The info about XML access is on this site and not under "ls-mods.de".
- Add the information about ..input(x)#name... to the documentation on this site under the Chapter XMLPath.
- Fix the missing or bad links in the documentation on this site.
- index to XML
- several Links to XMLPath
Note: Log in to post. Create a new account here.