Delete certain line in file... (dcdm)
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Delete certain line in file... (dcdm)

Started by JAM, 23 August, 2004, 19:04:59

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JAM

I'm trying to delete row no. from a certain file, using lua5 in dcdm. I'm however still very unfamiliar with the lua language, so I'm not really sure what to base my searches on trying to find the solution, so I'm hoping for guidance here...

Sofar I'm guessing one of the following (hope it enough to understand):

* Read each line into tmp (array?) during a loop and if i == linenumber, skip it and continue. In the end, truncate the file, and loop tmp to re-write the info...

* Read the file, at the same write the strings i get into a tmp-file, except for the mentioned line. In the end renaming the file.

* Make a single write("") when i == linenumber.

I'd post example code but I don't have it locally. I have tried all above myself, but I just cannot get it to work correctly. =/ Thanks in advance.
\"I do this for fun, so should all!\"

BottledHate

i think this is what u are tryign to do??? not sure
though... this reads a file.. removes the line number
 specified.. then re-saves the file without that line.

-------------------
local filename = "scripts/bleh.txt"
local lineToRemove = 10
-------------------
local lineN = 1
local tmp =""
for line in io.lines(filename) do
   if lineN ~= lineToRemove then
      tmp = tmp..line.."\r\n"
   end
lineN = lineN +1
end
local f,e = io.open( filename, "w+" )
if f then
   f:write( tmp )
   f:close()
end
-------------------

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

JAM

Precicely, thank you. It suddenly looks so easy, but I just couldn't figure it out... =/
\"I do this for fun, so should all!\"

BottledHate

np.. i'm here to help when i can... a month ago i wouldn't
have been able to help you...  ;) some good sources for learning are:

Plops Webpage -down atm.. but should be back up in a day or so.
Lua 5 Reference
and here on the forums in the Cleint Side Threads

-BH
Homepage: www.bottledhate.webhop.org

Compiling  Lua scripts is LAME!!!!!

SMF spam blocked by CleanTalk