Deleting text in a .txt file
 

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

Deleting text in a .txt file

Started by Mondy, 19 January, 2004, 16:10:45

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Mondy

What i need to do is delete all the text that is in the text file.  Or delete the text file itself.

I have been looking around these forums for the last hour or so trying to learn how to use the write command to do this (im not even sure if that command can do this).  I have had no success and any help would be appriciated.

Thankyou

plop

remove(filename)
that deletes the given file.
if you want 2 make it empty just start writing 2 it, if you don't say it has 2 append it overwrites everything.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Mondy

Well i cant even work out simple instrutions it seems.

This is what i have.
-----------------------------------
file = "text.txt"

function Main()
SetTimer(1000)
StartTimer()
end


function OnTimer()
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
say = (line)
end
end

SendToAll(say)
remove(text.txt)

end
--------------------------------------

i am getting this error
Syntax Error: attempt to index global `text' (a string value)

pHaTTy

hmm

remove(text.txt)   <<<

remove("text.txt")

OR

filename = "text.txt"
remove(filename)

l8rr
Resistance is futile!

Mondy

I just found the writeto(file) command before i only knew of the write().  That solved my problem.  I couldnt get the remove command to work.  Thanks for all the help i got anyway.

Heres the final script just incase anyone else needs this sort of thing.

file = "text.txt"

function Main()
SetTimer(1000)
StartTimer()
end


function OnTimer()
say = nil
readfrom(file)
while 1 do
local line = read()
if (line == nil) then
break
else
say = (line)
end
end
read()
SendToAll(say)
writeto(file)
end

Mondy

Well since i started using this thread for this script i might as well keep using it.  What iv been trying to create is a way for people to talk between an IRC channel and the Direct Connect channel.  Its working up to the point where in the direct connect channel whats being said is being echoed  e.g.

[14:07] not on ure side
[14:07] [IRC] > * not on ure side

What im trying to do now is get the script to parse out any lines that begin with "[IRC] > *"  The script that im using is included below and any help would be appreciated once again.  Thank you

file = "#irc.log"

function Main()
SetTimer(1000)
StartTimer()
end


function OnTimer()
say = nil
readfrom(file)
while 1 do
local line = read()
say = (line)

if (line == nil) then
  break
elseif (say == "[IRC] > * <") then
  break
else
  read()
  SendToAll(say)
  writeto(file)
end

plop

i got the idea that this is what you need.
prefix = { ["+"]=1,["!"]=1} --- insert all your command prefixes here
fileirc = "#irc.log"  ----- file from irc 2 be shown in dc
filedc = "dc.log"   ---- file from dc 2 be show in irc

function Main()
   SetTimer(1000)
   StartTimer()
end


function OnTimer()
   readfrom(fileirc)
   while 1 do
      local line = read()
      if (line == nil) then
         break
      else
         SendToAll(line)
      end
   end
   readfrom()
   remove(fileirc)
end

function DataArrival(user,data)
   if( strsub(data, 1, 1) == "<" ) then
      local tmp = strsub(data,1,1)
      if prefix[tmp]== nil then
         data=strsub(data,1,strlen(data)-1) 
         appendto(filedc)
         write("[DC] "..data)
         writeto()
      end
   end
end
as you can see it uses 2 files.
1) stuff from irc 2 be shown on dc.
2) stuff from dc 2 be shown on irc (commands are filtered).

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Mondy

#7
Thanks again its working now

plop

QuoteOriginally posted by Mondy
Thanks again its working now
yw.

can you post the irc part of this here so other ppl can use it 2 if they want ???
thx in adv.

plop
http://www.plop.nl lua scripts/howto\'s.
http://www.thegoldenangel.net
http://www.vikingshub.com
http://www.lua.org

>>----> he who fights hatred with hatred, drives the spreading of hatred <----<<

Mondy

Here are the Irc scripts.  [IRC] is used as a trigger to be parsed out.  

Theres this one.
/dc { if ( [IRC] isin $read("c:\path\to\log.log"))   /write -c ("c:\path\to\log.log")
  elseif (1 <= $lines(c:\path\to\log.log)) //msg #animesharensw $read("c:\path\to\log.log",$lines(c:\path\to\log.log))
  /write -c ("c:\path\to\log.log")
}

And this one

/dc {
  var %log = "c:\path\to\log.log"
  var %line = $read(%log, 1)
  while ($lines(%log) > 0) {
    if ($left(%line,7) != * [IRC]) /msg #animesharensw %line
    /write -dl1 %log
    %line = $read(%log, 1)
  }
}

SMF spam blocked by CleanTalk