mIRC Home    About    Download    Register    News    Help

Print Thread
#230726 18/03/11 10:05 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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.

Last edited by FroggieDaFrog; 18/03/11 10:07 PM.

I am SReject
My Stuff
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
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) }
}

hixxy #230730 18/03/11 11:00 PM
Joined: Apr 2010
Posts: 969
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
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- }
  }
}

Last edited by FroggieDaFrog; 19/03/11 12:12 AM.

I am SReject
My Stuff
Joined: Dec 2002
Posts: 344
D
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
$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.

drum #230735 19/03/11 01:43 AM
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
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).


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
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...


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Wims #230740 19/03/11 08:35 AM
Joined: Dec 2002
Posts: 344
D
Pan-dimensional mouse
Offline
Pan-dimensional mouse
D
Joined: Dec 2002
Posts: 344
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.

drum #230742 19/03/11 09:43 AM
Joined: Jul 2006
Posts: 4,144
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,144
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

Last edited by Wims; 19/03/11 09:45 AM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard