返回一个目录的相对路径
#Include <File.au3>
_PathGetRelative($sFrom, $sTo)
$sFrom | 源目录路径 |
$sTo | 目标路径文件或目录 |
成功: | 返回源目录的相对路径. | |
失败: | 返回目标对象,设置@error: | |
@error: | 1 - $sFrom 等于 $sTo | |
2 - $sFrom 的根驱动器与 $sTo 不同, 相对路径不能返回. |
#include <File.au3>
_Main()
Func _Main()
Local $from, $to, $path
Local $Wow64 = ""
If @AutoItX64 Then $Wow64 = "\Wow6432Node"
Local $sFile = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $Wow64 & "\AutoIt v3\AutoIt", "InstallDir")
$from = @ScriptDir
ConsoleWrite("Source Path: " & $from & @CRLF)
$to = $sFile & "\autoit3.exe"
ConsoleWrite("Dest Path: " & $to & @CRLF)
$path = _PathGetRelative($from, $to)
If @error Then
ConsoleWrite("Error: " & @error & @CRLF)
ConsoleWrite("Path: " & $path & @CRLF)
Else
ConsoleWrite("Relative Path: " & $path & @CRLF)
ConsoleWrite("Resolved Path: " & _PathFull($from & "\" & $path) & @CRLF)
EndIf
EndFunc ;==>_Main