mIRC Homepage
Posted By: cyter Checking if a file exists - 27/12/02 05:35 AM
Here's the code

on 1:TEXT:~test:#: {
if ($exists(c:\mirc\files\ $+ $nick $+ .txt) == $true) { msg $chan Exists } | else { msg $chan does not exist }
}

It always returns "does not exist". However, when I change $+ $nick $+ .txt to cyter.txt, it returns "Exists". I added a message to show what it was getting in the exist, and it told me c:\mirc\files\cyter.txt Any ideas what is wrong? I've asked several other people, but they couldn't figure out what was wrong.
Posted By: Hammer Re: Checking if a file exists - 27/12/02 05:39 AM
Code:

on 1:TEXT:~test:#: {
  if ($exists($+(c:\mirc\files\,$nick,.txt))) msg $chan Exists
  else msg $chan does not exist
}

You might also try using $mircdir or $scriptdir. cool

Posted By: NightChillz Re: Checking if a file exists - 27/12/02 06:28 AM
hmmm, i have always used "$isfile" to check if a file is there or not...


if ($isfile(thispath\thisfile)) { echo -a yes it is there }

simple example, lol
Posted By: Hammer Re: Checking if a file exists - 27/12/02 07:55 AM
You could also use $file(filename) as well. It will return $null if it is not found or 0 if the file is empty. You could even test for both conditions if you wanted to. smile
Code:

on *:TEXT:!exists*:#:{
  if ($file($+(",$mircdir,$$2-,.txt")) == $null) msg $chan $2 was not found.
  elseif ($file($+(",$mircdir,$2,.txt")) == 0) msg $chan $2 was found, but it's an empty file.
  else msg $chan $2 was found!
}

You could also use:

msg $chan $findfile(C:\,$+(",$2-,.txt"),0,msg $chan $nopath($1-) was found in $nofile($1-)) matches found for $2-

but that's getting a little out of hand, don't you agree? smirk
Posted By: cyter Re: Checking if a file exists - 27/12/02 02:45 PM
I appreciate the quick responses, and I tried out the $isfile and the $exists Hammer showed.

However, it still said no file exists. Once I changed the variable name to the file name, it said the file existed.

And for the first one, even when I replaced the variable name with the file, it still wouldn't work until I took out the $+
Posted By: Hammer Re: Checking if a file exists - 27/12/02 09:40 PM
Can you please show us exactly what you are using/typing? Unless we see the exactly syntax you are using for your example, we cannot possibly duplicate it, nor really explain it. The best we'll be able to do is take shots in the dark until one of us hits on a way to solve your particular problem - an iffy way to arrive at a satisfactory solution.
  • Try double-quoting your filename.

    var %filename = " $+ filenameOrVariable $+ "
    var %filename = $+(",filenameOrVariable,")
  • $crc(%filename) will return 00000000 if the file doesn't exists, which is $false in an if condition.
  • $exists(%filename) should works fine.
  • $file(%filename) should work fine.
  • $findfile($nofile(%directory),$nopath(%filename),1) should work fine.
  • $lines(%filename) should work fine.
  • $isfile(%filename) should work fine.
  • $longfn(%filename) should work fine.
  • $nopath(%filename) should work fine.
  • $read(%filename) should work fine.
  • $shortfn(%filename) should work fine.
Off the top of my head, I'd say it most likely has to do with how you're setting your variable but I wouldn't necessarily bet on it without a lot more information.
Posted By: cyter Re: Checking if a file exists - 28/12/02 04:11 AM
on 1:TEXT:~test:#: {
if ( $exists( c:\mirc\files\ $+ $nick $+ .txt )) { echo -a yes it is there } | else { echo -a no it is not there }
}

I was interested in seeing how $exists works, and wondered how you would do it with variables or the nickname of the person who tried it instead of typing the direct path. I made a text file named cyter.txt, and using the nickname cyter typed ~test. It kept telling me it didn't exist, but when I changed the path to c:\mirc\files\cyter.txt it told me it existed.

Don't know if mIRC versions has anything to do with it, but I'm using 5.82.

I probably still didn't answer your question, so if you have anything else to ask, I'll try to answer.
Posted By: Hammer Re: Checking if a file exists - 28/12/02 06:20 AM
v5.82? shocked Have you considered joining us in the 21st century? :tongue:
  1. 16 Aug 2002 - mIRC v6.03
  2. 06 Jun 2002 - mIRC v6.02
  3. 10 Feb 2002 - mIRC v6.01
  4. 03 Feb 2002 - mIRC v6.0
  5. 15 Jun 2001 - mIRC v5.91
  6. 26 Apr 2001 - mIRC v5.9
  7. 14 Dec 2000 - mIRC v5.82
2000 was the last year of the 20th century.
Posted By: cyter Re: Checking if a file exists - 28/12/02 03:22 PM
Wow, I think that might have been it. I decided to join you in the 21st century :tongue: and it turned out it now works. Thanks!
Posted By: codemastr Re: Checking if a file exists - 28/12/02 08:40 PM
Use $isfile, not $exists reason is, if I create a folder named $nick $+ .txt, $exists will return true, but it's not a file, it is a folder. $isfile only returns true if it is a file, it will return false if it either doesn't exist or is a folder.
Posted By: NightChillz Re: Checking if a file exists - 28/12/02 10:04 PM
lol, welcome to the 21st wink

yes, thats what i always use, $isfile, or $findfile, depending on what i am doing smile
© mIRC Discussion Forums