Author Topic: If File doesn?t exist...  (Read 1663 times)

0 Members and 1 Guest are viewing this topic.

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
If File doesn?t exist...
« on: 26 October, 2003, 17:20:23 »
Hi all,

I am trying to read a text file that was creating by other commands but i want to make a "if" when the file doesn?t exits to send a message.

For example

Code: [Select]
arg = GetARG()
local username = GetItemByName (arg)
text = "txt/"..arg..".txt"

if username == nil then
  if text == nil
    user:SendPM(Bot, "There is no info")
  else
    readfrom(text)
end
end

It is working good on the read file but when the file doesn?t exist is not sending the msg !!

Can anyone help me !!

Best regards, nErBoS



--## nErBoS Spot ##--

PtokaX forum

If File doesn?t exist...
« on: 26 October, 2003, 17:20:23 »

Offline tezlo

  • Triple Ace
  • **
  • Posts: 225
  • Karma: +1/-0
(No subject)
« Reply #1 on: 26 October, 2003, 18:24:13 »
you dont need to GetItemByName()
and you dont want to check if text == nil
because you just set it equal to "txt/"..arg..".txt" so its always a string
unless GetARG(whatever it does) returned nil and you got a concat error

it says in the manual that readfrom() returns nil on error so..
if not readfrom(text) then user:SendPM(Bot, "no info on "..arg)

but you might want to display the info or do whatever with it so..
local file = readfrom(text)
if not file then user:SendPM(Bot, "..
else user:SendPM(Bot, file) end

btw.. if not file is the same as if file == nil
have fun

Offline nErBoS

  • Emperor
  • **
  • Posts: 1 149
  • Karma: +3/-1
(No subject)
« Reply #2 on: 26 October, 2003, 18:31:50 »
Thanks for the explination and help !!

Best regrads, nErBoS
--## nErBoS Spot ##--

PtokaX forum

(No subject)
« Reply #2 on: 26 October, 2003, 18:31:50 »