Advertisement
SReject

Untitled

Jan 19th, 2020
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 1.38 KB | None | 0 0
  1. /*
  2. $ExpandPath([root,] path)
  3.     Returns $null if the path is invalid
  4.     Returns the expanded path
  5.  
  6.     root - optional
  7.         The root directory to use if path is not achored to a drive
  8.         If not specified $mircdir will be used
  9.  
  10.     path
  11.         The path to expand
  12. */
  13. alias ExpandPath {
  14.   var %n1 = $regsubex($1, /(?:^[\r\n ]+)|(?:[\r\n ]+$)/g,), %n2 = $regsubex($2, /(?:^[\r\n ]+)|(?:[\r\n ]+$)/g,), %drive, %path
  15.   if ($regex(%n2, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
  16.     %drive = $regml(1)
  17.     %path = $regml(2)
  18.   }
  19.   elseif ($0 > 1 && $regex(%n1 $+ \ $+ %n2, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
  20.     %drive = $regml(1)
  21.     %path = $regml(2)
  22.   }
  23.   elseif ($0 == 1 && $regex(%n1, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
  24.     %drive = $regml(1)
  25.     %path = $regml(2)
  26.   }
  27.   elseif ($0 == 1 && $regex($mircdir $+ %n1, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
  28.     %drive = $regml(1)
  29.     %path = $regml(2)
  30.   }
  31.   else {
  32.     return
  33.   }
  34.   if (!$isdir(%drive) || $regex(%path, /([\x{0000}-\x{001F}?*"<>\:|])/)) {
  35.     return
  36.   }
  37.   %path = $regsubex(%path, /[\\\/]+/g, \)
  38.   %path = $regsubex(%path, /(?:^|\\)(?:\.(?:\\|$))+/, \)
  39.   while ($regsubex(%path, /(?:^|\\)(?!\.\.(?:\\|$))[^\\]+\\\.\.(?:$|\\)/, \) != %path) {
  40.     %path = $v1
  41.   }
  42.   if (..\* !iswm %path && \..\ !isin %path) {
  43.     return $regsubex(%drive $+ \ $+ %path, /(?:\\(?=\\))|(?:[ .]+$)/g, )
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement