hi i searching:
function removes all symbolic links (like '\..\'
thanks
update:
first prototype:
ToolTip,% RegExReplace("\a\..\b\b\.\c\","\\[^\\\n]+\\\.\."),1,1
function removes all symbolic links (like '\..\'
function removes all symbolic links (like '\..\'
Last edited by SL5 on 24 Feb 2018, 05:31, edited 1 time in total.
github>g_IntelliSense + next improvements + forum
ahk..org>onlineAHKprettyfy, ahk..com>Refactoring
ahk..com>newposts Unanswrd myposts, Donations are appreciated if I could help you
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ahk..org>onlineAHKprettyfy, ahk..com>Refactoring
ahk..com>newposts Unanswrd myposts, Donations are appreciated if I could help you
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: function removes all symbolic links (like '/./', '/../' and extra '/') and returns the absolute pathname.
Code: Select all
Loop Files, %relativePath%, DF
MsgBox % A_LoopFileLongPath
Re: function removes all symbolic links (like '\..\'
Here's some RegEx code which is similar to yours, and an example with A_LoopFileLongPath. Btw is it just '\..\' or are there other things that need to be handled?
Code: Select all
;replace '\Subfolder\..\' with '\'
;C:\Users\me\AppData\Roaming\..\..\Documents
; ------------
;C:\Users\me\AppData\..\Documents
; ------------
;C:\Users\me\Documents
q:: ;relative paths to absolute paths
vPath := "C:\Users\" A_UserName "\AppData\Roaming\..\..\Documents"
;vPath := "C:\Users\" A_UserName "\AppData\Roaming\..\..\..\Public"
;vPath := "C:\Users\" A_UserName "\AppData\Roaming\..\..\..\..\Windows"
vPath2 := vPath
while InStr(vPath, "\..\")
;vPath := RegExReplace(vPath, "\\[^\\]+\Q\..\\E", "\") ;can fail e.g. if contains '\..\..\..\..\'
vPath := RegExReplace(vPath, "\\[^\\]*[^\\.]\Q\..\\E", "\") ;assumes folder names cannot end with '.'
MsgBox, % vPath
Loop, Files, % vPath2, FD
vPath2 := A_LoopFileLongPath
MsgBox, % vPath2
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: function removes all symbolic links (like '\..\'
update 26.02.2018 15:39
the Version with A_LoopFileLongPath works only for absoluthe path.
For e.g. this works not (never enters the loop.
update 26.02.2018 15:07:
I tried to remove the while and do it all with regex (was double faster). But i cant.
Your Version with InStr(vPath, "\..\") was much shorter.
I changed the code a little bit. May interesting vor you:
I like it because it's short and no new function needs to be declared. not so great maybe the intelligibility.
I learnd the:
"In a regular expression, all chars between the \Q and \E are escaped." (http://www.perlmonks.org/bare/?node_id=468052)
Nice it makes it more readable
Yes actually there eventually also some \.\ possible who i dont need.
the Version with A_LoopFileLongPath works only for absoluthe path.
For e.g. this works not (never enters the loop.
Code: Select all
relativePath := "AppData\Roaming\..\Documents"
Loop Files, %relativePath%, DF
MsgBox % A_LoopFileLongPath
update 26.02.2018 15:07:
I tried to remove the while and do it all with regex (was double faster). But i cant.
Your Version with InStr(vPath, "\..\") was much shorter.
I changed the code a little bit. May interesting vor you:
Code: Select all
if(1){
path =
(
C:\Users\me\AppData\Roaming\..\..\Documents
C:\Users\me\AppData\Roaming\..\..\.\Documents
C:\Users\me\AppData\Roaming\.\..\..\.\Documents
)
pathClean:=""
Loop,Parse,path,`n
{
p := A_LoopField
while(pLength <> StrLen(p)){
pLength := StrLen(p)
p := RegExReplace(p,"(\\[^\\]+\\\.\.)+")
}
pathClean .= p . "`n"
}
MsgBox,% pathClean
Reload
}
Thanks dear Gust! Thats really cleverGuest wrote:Code: Select all
Loop Files, %relativePath%, DF MsgBox % A_LoopFileLongPath
I like it because it's short and no new function needs to be declared. not so great maybe the intelligibility.
Thanks dear jeeswgjeeswg wrote:Here's some RegEx code which is similar to yours, and an example with A_LoopFileLongPath. Btw is it just '\..\' or are there other things that need to be handled?
I learnd the:
"In a regular expression, all chars between the \Q and \E are escaped." (http://www.perlmonks.org/bare/?node_id=468052)
Nice it makes it more readable
Yes actually there eventually also some \.\ possible who i dont need.
update 26.02.2018 14:30 show regex-Version is double faster:jeeswg wrote:Code: Select all
... vPath := RegExReplace(vPath, "\\[^\\]*[^\\.]\Q\..\\E", "\") ;assumes folder names cannot end with '.' ...
Code: Select all
t1 := A_TickCount
Loop,999
{
Loop Files, C:\Users\me\AppData\Roaming\..\Documents, DF
v := A_LoopFileLongPath
}
t2 := A_TickCount
result1 := A_LineNumber . ": " . t2 - t1 ; = 62
t1 := A_TickCount
Loop,999
{
v := "C:\Users\me\AppData\Roaming\..\Documents"
while InStr(v, "\..\")
v := RegExReplace(v,"\\[^\\]+\\\.\.")
}
t2 := A_TickCount
result2 := A_LineNumber . ": " . t2 - t1 ; = 62
Clipboard := result1 . "`n" . result2
MsgBox % Clipboard
log =
(
middle loong path:
9: 94
19: 62
very long path:
9: 188
19: 62
very short path:
9: 125
19: 62
9: 94
19: 31
)
github>g_IntelliSense + next improvements + forum
ahk..org>onlineAHKprettyfy, ahk..com>Refactoring
ahk..com>newposts Unanswrd myposts, Donations are appreciated if I could help you
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
ahk..org>onlineAHKprettyfy, ahk..com>Refactoring
ahk..com>newposts Unanswrd myposts, Donations are appreciated if I could help you
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Who is online
Users browsing this forum: Google [Bot], wilkster and 306 guests