mIRC Homepage
Posted By: FroggieDaFrog $IsRelative() - 18/03/11 10:05 PM
Format: $isRelative(path)[.dir|.file]
Return: The full path to specified directory|path or $false if it doesn't exist

If the .file prop is specified, then it should only check for direct and relative paths to a file
if the .dir prop is specified, then it should only check for direct and relative paths to a directory

It should try check to see if the path exists, and return the fullpath as such:
  • Is a direct path to a file
  • Is a direct path to a directory
  • Is a relative path to a file ($mircdirpath)
  • Is a relative path to a directory
  • If none match, $null should be returned.
Posted By: hixxy Re: $IsRelative() - 18/03/11 10:54 PM
Not a bad idea, quite easy to script though:

Code:
alias isrelative {
  var %type = $iif(*.* iswm $1,file,dir), %item = $iif($nopath($1) == $1,$mircdir $+ $1,$1)
  if ($prop == $null) || ($v1 == %type) { return $iif($($+($!is,%type,$chr(40),%item,$chr(41)),2),%item,$v1) }
}
Posted By: FroggieDaFrog Re: $IsRelative() - 18/03/11 11:00 PM
What I ended up using:
Code:
alias Fullpath {
  if ($isid && $0 == 1 && $regex($prop,/^(?:file|dir)?$/i)) {
    tokenize 32 $noqt($1-)
    if ($prop != dir && $isfile($1-)) { return $file($1-).longfn }
    if ($Prop != file && $isdir($1-)) { return $iif($isdir($mircdir $+ $1-),$Mircdir) $+ $1- }
  }
}
Posted By: drum Re: $IsRelative() - 19/03/11 01:25 AM
$longfn() will always give you an absolute path and works with both files and directories. You'd just need to combine it with $isfile, $isdir, or $exists.

The only thing it doesn't handle is to eliminate ".." (parent directory) references, i.e.:

Code:
//echo -a $longfn(C:\Program Files (x86)\mIRC\..\mIRC\)


will give you

C:\Program Files (x86)\mIRC\..\mIRC\

and not

C:\Program Files (x86)\mIRC\

but this might not be important for your purposes.
Posted By: Wims Re: $IsRelative() - 19/03/11 01:43 AM
It's not important for any purpose, ".." are handled anywhere, if you use ".." with files&path $identifiers, you just get your ".." in return (if what you used return a path or a file).
Posted By: argv0 Re: $IsRelative() - 19/03/11 07:17 AM
There are plenty of 4 line snippets that could be "useful" to a small number of people-- I don't think that inherently makes it deserving of bloating mIRC's builtin identifiers.

Especially when there are identifiers like $longfn...
Posted By: drum Re: $IsRelative() - 19/03/11 08:35 AM
Originally Posted By: Wims
It's not important for any purpose, [...]


That's a very absolute statement. Suppose you want to determine if two or more paths are equivalent (i.e., point to the same file). Consider this list of paths:

Code:
C:\Users\JohnDoe\AppData\Roaming\mIRC\scripts\script1.mrc
scripts\script1.mrc
C:\Users\JohnDoe\AppData\Roaming\mIRC\..\mIRC\scripts\script1.mrc


$longfn() could help to identify that the first two entries are the same file, but wouldn't help with the 3rd entry -- without some extra work at least.
Posted By: Wims Re: $IsRelative() - 19/03/11 09:43 AM
You get me wrong, having the ability to "resolve" path that contain these things could be useful, but the fact that currently, any path/files related identifiers doesn't get rid of these isn't a problem
© mIRC Discussion Forums