AutoHotkey Community

It is currently May 27th, 2012, 10:16 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 40 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: May 26th, 2007, 11:03 am 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
Thanks, here they are:

Code:
PathCombine(dir, file) {
   VarSetCapacity(dest, 260, 1) ; MAX_PATH
   DllCall("Shlwapi.dll\PathCombineA", "UInt", &dest, "UInt", &dir, "UInt", &file)
   Return, dest
}

UrlCombine(base, rel) {
   len := VarSetCapacity(dest, 2084, 1) ; INTERNET_MAX_URL_LENGTH
   DllCall("Shlwapi.dll\UrlCombineA", "Str", base, "Str", rel
      , "UInt", &dest, "UInt", &len
      , "UInt", 0x20000000) ; URL_ESCAPE_UNSAFE
   Return, dest
}


v1.1 released.

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2007, 3:51 pm 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
In case somebody is interested how to get full path name from relative path:

Code:
GetFullName( fn ) {
   static buf, i
   if !i
      i := VarSetCapacity(buf, 512)
   DllCall("GetFullPathNameA", "str", fn, "uint", 512, "str", buf, "str*", 0)
   return buf
}

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 26th, 2009, 9:02 pm 
Offline

Joined: January 29th, 2009, 9:50 pm
Posts: 483
Location: Belgium
but this wont work for commandline params like:
"\kokos\koko.ini" \komkommer\komkomer.ino %drive%\popop .\.\..\Kokosnoten ".\voelsprietten.iso" ..\..\.\koko\.\atoom

where %drive% is optional for my app

this works:

Code:
SplitPath, A_ScriptFullPath, exeNameExt, exeDir, exeExt, ExeName, ExeDrive

path1 = "\kokos\koko.ini" \komkommer\komkomer.ino `%drive`%\popop .\.\..\Kokosnoten ".\voelsprietten.iso" ..\..\.\koko\.\atoom
Relative2FullPath(Path1)
msgbox %path1%
Return
Relative2FullPath(ByRef Path) {
   global
   StringReplace,Path,Path,`%drive`%,%ExeDrive%,1
   StringReplace,Path,Path,% " \",% " " ExeDrive "\",1
   StringReplace,Path,Path,% """\","%ExeDrive%\,1
   StringReplace,Path,Path,% " .\",% " " A_ScriptDir "\",1
   StringReplace,Path,Path,% """.\","%A_ScriptDir%\,1
   StringReplace,Path,Path,% " ..\",% " " A_ScriptDir "\",1
   StringReplace,Path,Path,% "\.\",% "\",1
   StringReplace,Path,Path,% """..\","%A_ScriptDir%\,1
   loop
      {
      if Path not contains ..
         return
      StringSplit,PathArray,Path,\
      Path =
      x=0
      Loop, %PathArray0% ;Parse the array and remove one ..
         {
         If PathArray%A_Index% = ..
            x=1
         IfNotEqual,x,1,continue ;if there was no .. found go on
         prev = % A_Index - 1
         next = % A_Index + 1
         PathArray%prev% = % PathArray%next% ;put the next var in the previus var (koko\snoot\..\aap = koko\aap)
         if A_Index = %PathArray0% ; if we are at the end we remove 2 items from the list
            PathArray0 = % PathArray0 - 2
         }
      Loop, %PathArray0% ;put the array back in the Var
         {
         if A_Index = 1
            Path = % PathArray%A_Index% "\"
         else if A_Index = %PathArray0%
            Path = % Path PathArray%A_Index%
         else Path = % Path PathArray%A_Index% "\"
         }
      }
   return
   }


the good thing is even i understand it
hope this can helpe someone (and me if my computercrashes and i loose all data)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 25th, 2009, 6:50 am 
Offline

Joined: November 24th, 2008, 1:01 am
Posts: 2
Just today, I was working on a script and needed an absolute path from a relative one. Here's the solution I came up with. So far, it works perfectly. I can't guarantee that it works in all situations, but for my uses it has been working.

EDIT: I ended up making a new topic. http://www.autohotkey.com/forum/viewtopic.php?t=43623


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: May 27th, 2010, 7:55 am 
Offline

Joined: May 18th, 2010, 9:07 pm
Posts: 10
Hi toralf, Titan, or anyone else who understands this stuff, :)
I'm using the RelativePath function and was wondering--right now when one of the two paths is the drive root, it defaults to a drive-less absolute path (e.g. "/data"). I'd like to still get a path relative to the other one given, though ("../data" or whatever). How hard might it be to change this behavior in the function?

Thanks!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 19th, 2010, 1:48 am 
Offline

Joined: May 18th, 2010, 9:07 pm
Posts: 10
It took some studying and some trial-and-error (mostly the latter), but I think I figured out how to change the function to work the way I was hoping, if anyone is curious:

Code:
FindRelativePathFunction(HomePath, RemotePath, s="\"){
    len := InStr(HomePath, s, "", InStr(HomePath, s . s) + 2) ;get server or drive string length
    If SubStr(HomePath, 1, len ) <> SubStr(RemotePath, 1, len )  ;different server or drive
        Return RemotePath                                              ;return absolute path
;    HomePath := SubStr(HomePath, len + 1 )                    ;remove server or drive from HomePath
;    RemotePath := SubStr(RemotePath, len + 1 )                      ;remove server or drive from RemotePath
    If InStr(HomePath, s, "", 0) = StrLen(HomePath)           ;remove last \ from HomePath if any
        StringTrimRight, HomePath, HomePath, 1
    If InStr(RemotePath, s, "", 0) = StrLen(RemotePath)             ;remove last \ from RemotePath if any
        StringTrimRight, RemotePath, RemotePath, 1
    Loop{
 ;       If !HomePath                                            ;when there is nothing identical
  ;          Return s RemotePath                                         ;return RemotePath in root
        If InStr(RemotePath s, HomePath s){                      ;when parts of paths match
            If !r                                                      ;no relative part yet
                r = .%s%                                                   ;RemotePath is in the HomePath
            Return r . SubStr(RemotePath,StrLen(HomePath) + 2)        ;return relative path
        }Else{                                                    ;otherwise
            r .= ".." s                                                ;add relative part
            HomePath := SubStr(HomePath, 1, InStr(HomePath, s, "", 0) - 1)   ;remove one folder from HomePath
          }
      }
  }


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 12th, 2010, 4:01 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I want add these into my library. I think about to combine the two functions RelativePath() and AbsolutePath() into one library. Because they cover a very specific field, I am reluctant to name the file and prefix "Path". I am reserving "Path" to a more general library.

Or should I make two separate files without a prefix? The two are very similiar and changed and maintained by same date and authors and released under same topic. So combining would be natural.

What would you propose to do? Here are some ideas:
    path_getRelative()
    path_getAbsolute()

    rootPath_Relative()
    rootPath_Absolute()
rp for relative or root path
    rp_RelativePath()
    rp_AbsolutePath()


EDIT: I decided to use RPath_Relative() and RPath_Absolute().

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
PostPosted: June 1st, 2011, 3:38 pm 
Offline

Joined: May 29th, 2011, 3:06 am
Posts: 85
I was trying to use the RPath_Absolute() function to allow paths (optionally) relative to the script directory to be specified when loading settings from a file and came across a couple of problems.
  1. It stripped trailing slashes from the relative path. E.g
    Code:
    RPath=..\Folder\
    APath=D:\Temp
    Result=D:\Folder     ;No trailing slash
  2. If an already absolute path which did not require any substitution was supplied it just joined the 2 in a bit of a mess. E.g
    Code:
    RPath=D:\Folder
    APath=D:\Temp
    Result=D:\Temp\D:\Folder    ;I think it should just return D:\Folder
Now, I'm not sure if any of this behavior is by design, but it was not doing what I needed so I modified the function to work like I thought it should in these two cases. Other than no longer stripping the trailing slash I believe it will work as it did before. That being said, I'm not 100% sure on all the things it was meant to do before either.

Here's the modified version
Code:
; Modified: AbsolutePath
RPath_Absolute(AbsolutPath, RelativePath, s="\") {
   
    len := InStr(AbsolutPath, s, "", InStr(AbsolutPath, s . s) + 2) - 1   ;get server or drive string length
    pr := SubStr(AbsolutPath, 1, len)                                     ;get server or drive name
    AbsolutPath := SubStr(AbsolutPath, len + 1)                           ;remove server or drive from AbsolutPath
    If InStr(AbsolutPath, s, "", 0) = StrLen(AbsolutPath)                 ;remove last \ from AbsolutPath if any
        StringTrimRight, AbsolutPath, AbsolutPath, 1
   
    If InStr(RelativePath, s) = 1                                         ;when first char is \ go to AbsolutPath of server or drive
        AbsolutPath := "", RelativePath := SubStr(RelativePath, 2)        ;set AbsolutPath to nothing and remove one char from RelativePath
    Else If InStr(RelativePath,"." s) = 1                                 ;when first two chars are .\ add to current AbsolutPath directory
        RelativePath := SubStr(RelativePath, 3)                           ;remove two chars from RelativePath
    Else If InStr(RelativePath,".." s) = 1 {                              ;otherwise when first 3 char are ..\
        StringReplace, RelativePath, RelativePath, ..%s%, , UseErrorLevel     ;remove all ..\ from RelativePath
        Loop, %ErrorLevel%                                                    ;for all ..\
            AbsolutPath := SubStr(AbsolutPath, 1, InStr(AbsolutPath, s, "", 0) - 1)  ;remove one folder from AbsolutPath
    } Else                                                                ;relative path does not need any substitution
        pr := "", AbsolutPath := "", s := ""                              ;clear all variables to just return RelativePath

    Return, pr . AbsolutPath . s . RelativePath                           ;concatenate server + AbsolutPath + separator + RelativePath
}

And here's a script like the example to test the original vs modified
Code:
PathA = \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR = .\..\SmartGui\no_commit\icons_dev\
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "> RPath_Absolute(PathA, PathR)`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR) . "`n"
MsgText .= "Note trailing slash got stripped from path in original version.`n`n"

PathA = \\server.com\user\Files\Docs\Code\AHK\
PathR = D:\Path\Which\Requires\No\Substitution.exe
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "> RPath_Absolute(PathA, PathR)`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR) . "`n"
MsgText .= "Note the original version did not handle case of path which was already absolute too well.`n`n"

PathA = \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR = ..\..\SmartGui\no_commit\icons_dev
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR) . "`n`n"

PathA = \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR = .\..\SmartGui\no_commit\icons_dev
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR) . "`n`n"

PathA = \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR = \SmartGui\no_commit\icons_dev
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR) . "`n`n"

PathA = \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR = ..\..\SmartGui\no_commit\icons_dev\
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR) . "`n`n"

PathA = \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR = .\..\SmartGui\no_commit\icons_dev\
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR) . "`n`n"

PathA = \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR = \SmartGui\no_commit\icons_dev\
MsgText .= "PathA=" PathA "`nPathR=" PathR "`n"
MsgText .= "Original:  " RPath_Absolute_Original(PathA, PathR) . "`n"
MsgText .= "Modified: " RPath_Absolute_Modified(PathA, PathR)

MsgBox %MsgText%



; Modified: AbsolutePath
RPath_Absolute_Modified(AbsolutPath, RelativePath, s="\") {
   
    len := InStr(AbsolutPath, s, "", InStr(AbsolutPath, s . s) + 2) - 1   ;get server or drive string length
    pr := SubStr(AbsolutPath, 1, len)                                     ;get server or drive name
    AbsolutPath := SubStr(AbsolutPath, len + 1)                           ;remove server or drive from AbsolutPath
    If InStr(AbsolutPath, s, "", 0) = StrLen(AbsolutPath)                 ;remove last \ from AbsolutPath if any
        StringTrimRight, AbsolutPath, AbsolutPath, 1
   
    If InStr(RelativePath, s) = 1                                         ;when first char is \ go to AbsolutPath of server or drive
        AbsolutPath := "", RelativePath := SubStr(RelativePath, 2)        ;set AbsolutPath to nothing and remove one char from RelativePath
    Else If InStr(RelativePath,"." s) = 1                                 ;when first two chars are .\ add to current AbsolutPath directory
        RelativePath := SubStr(RelativePath, 3)                           ;remove two chars from RelativePath
    Else If InStr(RelativePath,".." s) = 1 {                              ;otherwise when first 3 char are ..\
        StringReplace, RelativePath, RelativePath, ..%s%, , UseErrorLevel     ;remove all ..\ from RelativePath
        Loop, %ErrorLevel%                                                    ;for all ..\
            AbsolutPath := SubStr(AbsolutPath, 1, InStr(AbsolutPath, s, "", 0) - 1)  ;remove one folder from AbsolutPath
    } Else                                                                ;relative path does not need any substitution
        pr := "", AbsolutPath := "", s := ""                              ;clear all variables to just return RelativePath

    Return, pr . AbsolutPath . s . RelativePath                           ;concatenate server + AbsolutPath + separator + RelativePath
}


; Original: AbsolutePath
RPath_Absolute_Original(AbsolutPath, RelativePath, s="\") {
    len := InStr(AbsolutPath, s, "", InStr(AbsolutPath, s . s) + 2) - 1   ;get server or drive string length
    pr := SubStr(AbsolutPath, 1, len)                                     ;get server or drive name
    AbsolutPath := SubStr(AbsolutPath, len + 1)                           ;remove server or drive from AbsolutPath
    If InStr(AbsolutPath, s, "", 0) = StrLen(AbsolutPath)                 ;remove last \ from AbsolutPath if any
        StringTrimRight, AbsolutPath, AbsolutPath, 1
    If InStr(RelativePath, s, "", 0) = StrLen(RelativePath)               ;remove last \ from RelativePath if any
        StringTrimRight, RelativePath, RelativePath, 1
    If InStr(RelativePath, s) = 1                                         ;when first char is \ go to AbsolutPath of server or drive
        AbsolutPath := "", RelativePath := SubStr(RelativePath, 2)            ;set AbsolutPath to nothing and remove one char from RelativePath
    Else If InStr(RelativePath,"." s) = 1                                 ;when first two chars are .\ add to current AbsolutPath directory
        RelativePath := SubStr(RelativePath, 3)                               ;remove two chars from RelativePath
    Else {                                                                ;otherwise
        StringReplace, RelativePath, RelativePath, ..%s%, , UseErrorLevel     ;remove all ..\ from RelativePath
        Loop, %ErrorLevel%                                                    ;for all ..\
            AbsolutPath := SubStr(AbsolutPath, 1, InStr(AbsolutPath, s, "", 0) - 1)  ;remove one folder from AbsolutPath
      }
    Return, pr . AbsolutPath . s . RelativePath                             ;concatenate server + AbsolutPath + separator + RelativePath
  }

which gave the following (AHK_L 1.1.0.0)
Code:
PathA=\\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR=.\..\SmartGui\no_commit\icons_dev\
> RPath_Absolute(PathA, PathR)
Original: \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes\..\SmartGui\no_commit\icons_dev
Modified: \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes\..\SmartGui\no_commit\icons_dev\
Note trailing slash got stripped from path in original version.

PathA=\\server.com\user\Files\Docs\Code\AHK\
PathR=D:\Path\Which\Requires\No\Substitution.exe
> RPath_Absolute(PathA, PathR)
Original: \\server.com\user\Files\Docs\Code\AHK\D:\Path\Which\Requires\No\Substitution.exe
Modified: D:\Path\Which\Requires\No\Substitution.exe
Note the original version did not handle case of path which was already absolute too well.

PathA=\\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR=..\..\SmartGui\no_commit\icons_dev
Original: \\server.com\user\Files\Docs\Code\AHK\SmartGui\no_commit\icons_dev
Modified: \\server.com\user\Files\Docs\Code\AHK\SmartGui\no_commit\icons_dev

PathA=\\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR=.\..\SmartGui\no_commit\icons_dev
Original: \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes\..\SmartGui\no_commit\icons_dev
Modified: \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes\..\SmartGui\no_commit\icons_dev

PathA=\\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR=\SmartGui\no_commit\icons_dev
Original: \\server.com\SmartGui\no_commit\icons_dev
Modified: \\server.com\SmartGui\no_commit\icons_dev

PathA=\\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR=..\..\SmartGui\no_commit\icons_dev\
Original: \\server.com\user\Files\Docs\Code\AHK\SmartGui\no_commit\icons_dev
Modified: \\server.com\user\Files\Docs\Code\AHK\SmartGui\no_commit\icons_dev\

PathA=\\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR=.\..\SmartGui\no_commit\icons_dev\
Original: \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes\..\SmartGui\no_commit\icons_dev
Modified: \\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes\..\SmartGui\no_commit\icons_dev\

PathA=\\server.com\user\Files\Docs\Code\AHK\SciTEDirector\includes
PathR=\SmartGui\no_commit\icons_dev\
Original: \\server.com\SmartGui\no_commit\icons_dev
Modified: \\server.com\SmartGui\no_commit\icons_dev\
BTW, the original I got from the standard library collection thing which I'd just downloaded (2010 Sep it says at the top).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 14th, 2011, 3:22 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Thx, I`ll add a link to the modified version. If more experienced users confirm your changes to be ok (without sideffects), I update the Collection with your mod.

_________________
{1:"ahkstdlib", 2:"my libs", 3:"my apps", 4:"my license"}
--> Don't feed the troll! <--


Report this post
Top
 Profile  
Reply with quote  
PostPosted: May 1st, 2012, 4:19 pm 
Offline

Joined: December 2nd, 2010, 12:25 am
Posts: 73
Location: Ontario, Canada
emmanuel d I have found your function did not seem to work with a simple relative path such as Path1 := "..\scripts"
If however I added a space in front of a simple path such as Path1 := " ..\scripts" then it worked. I changed the function around a bit to work in both cases.
I changed your %drive% to %d simply because it worked with my scirpt

Code:
; %d is placeholder for Script Drive Letter
path1 = "\kokos\koko.ini" \komkommer\komkomer.ino `%d\popop .\.\..\Kokosnoten ".\voelsprietten.iso" ..\..\.\koko\.\atoom
dir := RelativeToFullPath(Path1)
MsgBox % dir

TC := "D:\Users\Paul\Documents\AutoHotkey\Scripts\Shortcuts"
dir := GetRelativePath(A_ScriptFullPath,TC)
MsgBox % dir

dir := RelativeToFullPath(dir)
MsgBox % dir

; Get the Relative path from Full Path
; From the Full Path often will be A_ScriptDir
; To: The destination path to get Relative Path
; Return Relative Path in a format such as ..\..\MyApps
GetRelativePath(from, to)
 {
   VarSetCapacity(pszPath,MAX_PATH:=260)
   if DllCall("Shlwapi\PathRelativePathTo"
      , "PTR", &pszPath
      , "STR", from
      , "UInt", InStr(from,"D")?FILE_ATTRIBUTE_DIRECTORY:=16:0
      , "Str", To
      , "UInt", InStr(to,"D")?FILE_ATTRIBUTE_DIRECTORY:0)
    {
      return StrGet(&pszPath)
    }
   else
    {
      return -1
    }
 }

; Converts a Relative Path into a full path
; %d can be used as a placeholder for the drive letter eg: %d\Program Files
; Returns the expanded path from a relative path passe in
RelativeToFullPath(Path) {
   Script_Drive := SubStr(A_ScriptDir,1,1) . ":"
   if (!Path) {
   return Path
   }
   NewPath := Path
   ; Function expects to see a space at the beginning of the path or it will fail on
   ; paths the begin with a .(dot)
   DotPos := InStr(NewPath,".")
   if (DotPos = 1){
   NewPath := " " . NewPath
   }
   StringReplace,NewPath,NewPath,`%d,%Script_Drive%,1
   StringReplace,NewPath,NewPath,% " \",% " " Script_Drive "\",1
   StringReplace,NewPath,NewPath,% """\","%Script_Drive%\,1
   StringReplace,NewPath,NewPath,% " .\",% " " A_ScriptDir "\",1
   StringReplace,NewPath,NewPath,% """.\","%A_ScriptDir%\,1
   StringReplace,NewPath,NewPath,% " ..\",% " " A_ScriptDir "\",1
   StringReplace,NewPath,NewPath,% "\.\",% "\",1
   StringReplace,NewPath,NewPath,% """..\","%A_ScriptDir%\,1

   loop
   {
      if NewPath not contains ..
         return Trim(NewPath)
      StringSplit,PathArray,NewPath,\
      NewPath =
      x=0
      Loop, %PathArray0% ;Parse the array and remove one ..
      {
         If (PathArray%A_Index% = ..) {
            x=1
         }
         if (x <> 1) {
            continue ;if there was no .. found go on
         }
         prev = % A_Index - 1
         next = % A_Index + 1
         PathArray%prev% = % PathArray%next% ;put the next var in the previus var (koko\snoot\..\aap = koko\aap)
         if (A_Index = PathArray0) { ; if we are at the end we remove 2 items from the list
            PathArray0 = % PathArray0 - 2
         }
      }
      Loop, %PathArray0% ;put the array back in the Var
      {
         if A_Index = 1
            NewPath = % PathArray%A_Index% "\"
         else if A_Index = %PathArray0%
            NewPath = % NewPath PathArray%A_Index%
         else NewPath = % NewPath PathArray%A_Index% "\"
         }
   }
   NewPath := Trim(NewPath)
   return NewPath
}


This seems to work in my initial test just fine.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 40 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: specter333, XX0 and 25 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group