mIRC Homepage
Posted By: Axis $exists() return $false for some filename - 19/01/07 09:06 AM
Hello..
i found bug when using $exists in mirc 6.21. The filename like
"ip.txt" , "ip.html", "ip.dll" return $false even that the file exists in mirc folder. eek eek
Posted By: Smay Re: $exists() return $false for some filename - 19/01/07 09:41 AM
Confirmed on my machine. Same goes for $isfile().

If you want a hacky workaround, you can use the $file command, e.g.:
Code:
if ($file(ip.txt).size == $null) {
  echo File doesn't exist
}

I don't know the reasoning behind this, but I'm sure it was intentional. You also cannot /write ip.txt test and perhaps other commands as well. You can always just use somthing other than ip.txt as a filename.
This is related to Windows/DOS device names. In DOS there are devices named CON, AUX, COM[1-9], LPT[1-9], PRN, and NUL which prevents any filename in DOS or Windows having a file with those names (with or without any file extension).

It's been suggested in the past by Khaled that this is also true for ip, global, shadow - and certainly mIRC does treat those filenames the same way (which is the reason for your bug). However I can't find any documentation explaining why those three additional files are reserved and I can't find any other application that prevents their use. Maybe Khaled or someone else can provide a link to where this is documented?
Posted By: Sat Re: $exists() return $false for some filename - 19/01/07 04:31 PM
Basically mIRC uses a Windows API call to check if a filename is a DOS device; if so, it will not allow access to that file. That Windows API call is not actually meant to be used this way though, as it also returns device names that cannot be used like filenames in the way that CON, NUL etc can. As it happens, those "ip", "global", "shadow" names are such device names used by Windows. You can get the full list (which differs from system to system) with this utility.
Ah, thanks. I spent an age trying to find something linking those words to device names. There's so much crap in MS's Win32 API documentation I couldn't find anything useful just searching through MSDN.

As you say, they're not the same as the "universal" device names NUL, CON, etc. so mIRC shouldn't really be checking for them. Seems like a bug that's overdue to be fixed...
Hi,

yes, but there must be a different. I have devices Names such as "Ip" and "TrueCrypt", but it's possible to access any file like "Ip.txt" or just "Ip".

Writing a a file "con.txt" raises an error. So, "Ip" may be be a device name, but it is accessable as a normal file using the command line or the explorer. I am not sure what mirc is doing, but it is not transparent for the user and I would call it a bug.
Posted By: Khaled Re: $exists() return $false for some filename - 22/01/07 02:02 PM
mIRC asks Windows whether the file name in question is a device name or not. If Windows says that it is a device, mIRC will prevent access to it. There's nothing more to it than that :-)
Posted By: Sat Re: $exists() return $false for some filename - 22/01/07 02:46 PM
The point was that not (by far) all device names are actually recognized as device names by Windows' file operations, and therefore the file names that happen to be device names are blocked unnecessarily.

The fact that Windows says that a name is a device, doesn't automatically mean that the name can't also be used as normal filename.
© mIRC Discussion Forums