If File doesn?t exist...
 

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

If File doesn?t exist...

Started by nErBoS, 26 October, 2003, 17:20:23

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

nErBoS

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

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 ##--

tezlo

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

nErBoS

Thanks for the explination and help !!

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

SMF spam blocked by CleanTalk