Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- $ExpandPath([root,] path)
- Returns $null if the path is invalid
- Returns the expanded path
- root - optional
- The root directory to use if path is not achored to a drive
- If not specified $mircdir will be used
- path
- The path to expand
- */
- alias ExpandPath {
- var %n1 = $regsubex($1, /(?:^[\r\n ]+)|(?:[\r\n ]+$)/g,), %n2 = $regsubex($2, /(?:^[\r\n ]+)|(?:[\r\n ]+$)/g,), %drive, %path
- if ($regex(%n2, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
- %drive = $regml(1)
- %path = $regml(2)
- }
- elseif ($0 > 1 && $regex(%n1 $+ \ $+ %n2, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
- %drive = $regml(1)
- %path = $regml(2)
- }
- elseif ($0 == 1 && $regex(%n1, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
- %drive = $regml(1)
- %path = $regml(2)
- }
- elseif ($0 == 1 && $regex($mircdir $+ %n1, /^([a-z\d![\]\\^_`]:)[\\\/]*(.*)$/i)) {
- %drive = $regml(1)
- %path = $regml(2)
- }
- else {
- return
- }
- if (!$isdir(%drive) || $regex(%path, /([\x{0000}-\x{001F}?*"<>\:|])/)) {
- return
- }
- %path = $regsubex(%path, /[\\\/]+/g, \)
- %path = $regsubex(%path, /(?:^|\\)(?:\.(?:\\|$))+/, \)
- while ($regsubex(%path, /(?:^|\\)(?!\.\.(?:\\|$))[^\\]+\\\.\.(?:$|\\)/, \) != %path) {
- %path = $v1
- }
- if (..\* !iswm %path && \..\ !isin %path) {
- return $regsubex(%drive $+ \ $+ %path, /(?:\\(?=\\))|(?:[ .]+$)/g, )
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement