Your function returns the exact input.
Code: Select all
path_getFullPath( pPath )
{
Static FirstRun, EnvVariables := "APPDATA|WinDir|AllUsersProfile|CLIENTNAME|CommonProgramFiles|COMPUTERNAME|HOMEDRIVE|HOMEPATH|LOGONSERVER|SESSIONNAME|SystemDrive|SystemRoot|USERDOMAIN|USERNAME|USERPROFILE|LOCALAPPDATA|ProgramData|PSModulePath|PUBLIC|TEMP|TMP|windows_tracing_logfile|Path"
;Resolve environment variables:
if !FurstRun
{
FurstRun := 1
Loop, Parse,EnvVariables,|
EnvGet,%A_loopfield%, %A_loopfield%
}
ifEqual,pPath,,Return
Loop, Parse,EnvVariables,|
if ( subStr( pPath, 1, strLen( A_LoopField )+2 ) = "`%" A_LoopField "`%" )
StringReplace,pPath,pPath,`%%A_LoopField%`%,% %A_LoopField%
; BuiltInVariables:
BuiltInVariables = Desktop|DesktopCommon|ProgramFiles|MyDocuments|Startup|Programs|StartMenuCommon|StartMenu|AppDataCommon
Loop, Parse,BuiltInVariables,|
if ( subStr( pPath, 1, strLen( A_LoopField )+2 ) = "`%" A_LoopField "`%" )
StringReplace,pPath,pPath,`%%A_LoopField%`%,% A_%A_LoopField%
; Prepare:
SplitPath, A_ScriptFullPath,,,,, ScriptDrive
While Instr( pPath, "\.\" )
StringReplace,pPath,pPath,\.\,\,All
While RegExMatch( pPath, "\\{3}" )
StringReplace,pPath,pPath,\\\,\\,All
; replace "\\" with "\" if its not in the beginning
a_path := pPath
start := subStr( pPath,1,2 )
rest := subStr( pPath,3 )
while inStr( rest, "\\" ) ;regExReplace( a_loopfield, "\\+","\" )
StringReplace,rest,rest,\\,\,All
pPath := start . rest
; param is already a full path
If RegExMatch( pPath, "i )^[a-z]:\\" )
finalePath := pPath
; param starts with "?\" or "?:\"
else if RegExMatch( pPath, "^\?" )
{
DriveGet, Drivelist, list
Loop, Parse, Drivelist
If ( FileExist( P:= A_Loopfield . Substr( pPath, 2 ) ) || FileExist( P:= A_Loopfield ":" Substr( pPath, 2 ) ) )
{
finalePath := P
break
}
}
; param starts with "\", relative to script drive
else If RegExMatch( pPath, "^\\[^\\]" )
finalePath := ScriptDrive . pPath
; param starts with "\\", network drive
else if RegExMatch( pPath, "^\\{2}" )
finalePath := pPath
; param starts with "%DRIVE%", relative to script drive
else If ( Substr( pPath, 1, 7 ) = "`%DRIVE`%" )
finalePath := RegExReplace( pPath, "i )%DRIVE%", ScriptDrive )
; param starts with ".\", relative to script subfolder
else if RegExMatch( pPath, "^\.\\" )
finalePath := A_workingDir . Substr( pPath, 2 )
; param starts with "..\", relative to script folder
else if RegExMatch( pPath, "^\.{2}\\" )
{
OutDir := A_workingDir
while RegExMatch( pPath, "^\.{2}\\" )
{
if ( ScriptDrive = OutDir )
return,,ReturnFrom:= A_LineNumber ;" ..\ was passed but resolved above the drive"
SplitPath, OutDir,, OutDir ; 1 dir UP
pPath := Substr( pPath,4 ) ; remove the ..\
}
finalePath := OutDir "\" pPath, ReturnFrom:= A_LineNumber ;" ..\ at the start was passed"
}
;Strip it of ending "\" unless it's a network path that isn't just "\\"
while ( subStr( finalePath,0 )="\" ) && !( subStr( finalePath,1 )="\\" )
finalePath := subStr( finalePath, 1,-1 )
Return finalePath
}