Jump to content

Search the Community

Showing results for tags 'winapiex pathgetrelative'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • General
    • Announcements and Site News
    • Administration
  • AutoIt v3
    • AutoIt Help and Support
    • AutoIt Technical Discussion
    • AutoIt Example Scripts
  • Scripting and Development
    • Developer General Discussion
    • Language Specific Discussion
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Categories

  • AutoIt Team
    • Beta
    • MVP
  • AutoIt
    • Automation
    • Databases and web connections
    • Data compression
    • Encryption and hash
    • Games
    • GUI Additions
    • Hardware
    • Information gathering
    • Internet protocol suite
    • Maths
    • Media
    • PDF
    • Security
    • Social Media and other Website API
    • Windows
  • Scripting and Development
  • IT Administration
    • Operating System Deployment
    • Windows Client
    • Windows Server
    • Office

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Member Title


Location


WWW


Interests

Found 1 result

  1. This post is not a request to change the following functions in the File.au3 UDF but about looking at an alternative route to getting the same results of the respective functions. As the idiom says "There's more than one way to skin a cat." Note: For these functions to work correctly you will require to be added to either the Include folder located in the install path of AutoIt or the location of where you save these functions. Even though some of these examples aren't 'speedy' I decided to create them anyway to showcase that the Windows API has a lot to offer when creating an application or code. In the past I've found that after creating a convoluted function that a simple API call would've been suffice. My gratitude goes towards Yashied as well as the author(s) of the original functions (in File.au3) as without the initial idea(s) I wouldn't have created these functions. Any comments or suggestions then please post below. Thanks. Example use of _PathSplitEx: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <Array.au3> #include <File.au3> #include <WinAPIEx.au3> ; Download From http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. Local $aArray = 0, $hTimer = 0, $sDirectory = '', $sDrive = '', $sExtension = '', $sFileName = '' ; Variables to be used with _PathSplit() & _PathSplitEx() $hTimer = TimerInit() $aArray = _PathSplit(@ScriptFullPath, $sDrive, $sDirectory, $sFileName, $sExtension) $hTimer = TimerDiff($hTimer) ConsoleWrite('Orignal: ' & @ScriptFullPath & @CRLF & _ 'Drive: ' & $sDrive & @CRLF & _ 'Directory: ' & $sDirectory & @CRLF & _ 'FileName: ' & $sFileName & @CRLF & _ 'Extension: ' & $sExtension & @CRLF & _ '_PathSplit Time: ' & $hTimer & @CRLF & @CRLF) _ArrayDisplay($aArray, '_PathSplit in AutoIt') $hTimer = TimerInit() $aArray = _PathSplitEx(@ScriptFullPath, $sDrive, $sDirectory, $sFileName, $sExtension) $hTimer = TimerDiff($hTimer) ConsoleWrite('Orignal: ' & @ScriptFullPath & @CRLF & _ 'Drive: ' & $sDrive & @CRLF & _ 'Directory: ' & $sDirectory & @CRLF & _ 'FileName: ' & $sFileName & @CRLF & _ 'Extension: ' & $sExtension & @CRLF & _ '_PathSplitEx() Time: ' & $hTimer & @CRLF & @CRLF) _ArrayDisplay($aArray, '_PathSplitEx by guinness') Func _PathSplitEx($sFilePath, ByRef $sDrive, ByRef $sDirectory, ByRef $sFileName, ByRef $sExtension) ; Created by guinness with the idea from _PathSplit(). Local $aReturn[5] = [$sFilePath, _ StringTrimRight(_WinAPI_PathStripToRoot($sFilePath), 1), _ ; Required to mimic the return style of _PathSplit(). _WinAPI_PathRemoveBackslash() doesn't work on the drive path. '' & _WinAPI_PathSkipRoot(_WinAPI_PathRemoveFileSpec($sFilePath)) & '', _ ; are required to mimic the return style of _PathSplit(). _WinAPI_PathStripPath(_WinAPI_PathRemoveExtension($sFilePath)), _ _WinAPI_PathFindExtension($sFilePath)] $sDrive = $aReturn[1] $sDirectory = $aReturn[2] $sFileName = $aReturn[3] $sExtension = $aReturn[4] Return $aReturn EndFunc ;==>_PathSplitExExample use of _PathGetRelativeEx: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <File.au3> #include <WinAPIEx.au3> ; Download From http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. Local $hTimer = 0, $sFilePath = '' $hTimer = TimerInit() $sFilePath = _PathGetRelative(@ScriptDir, @ScriptFullPath) $hTimer = TimerDiff($hTimer) ConsoleWrite('Original Path: ' & @ScriptFullPath & @CRLF & _ 'Relative Path: ' & $sFilePath & @CRLF & _ '_PathGetRelative() Time: ' & $hTimer & @CRLF & @CRLF) $hTimer = TimerInit() $sFilePath = _PathGetRelativeEx(@ScriptDir, @ScriptFullPath) $hTimer = TimerDiff($hTimer) ConsoleWrite('Original Path: ' & @ScriptFullPath & @CRLF & _ 'Relative Path: ' & $sFilePath & @CRLF & _ '_PathGetRelativeEx() Time: ' & $hTimer & @CRLF & @CRLF) Func _PathGetRelativeEx($sFrom, $sTo) ; Created by guinness with the idea from _PathGetRelative(). Local $iIsFolder = 0 If _WinAPI_PathIsDirectory($sTo) Then ; Check the destination path is a directory or file path. $sTo = _WinAPI_PathAddBackslash($sTo) ; Add a backslash to the directory. $iIsFolder = 1 EndIf Local $sRelativePath = _WinAPI_PathRelativePathTo(_WinAPI_PathAddBackslash($sFrom), 1, $sTo, $iIsFolder) ; Retrieve the relative path. If @error Then Return SetError(1, 0, $sTo) EndIf If $sRelativePath = '.' Then $sRelativePath &= '' ; This is used when the source and destination are the same directory. EndIf Return $sRelativePath EndFunc ;==>_PathGetRelativeExExample use of _PathFullEx: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w 7 #include <File.au3> #include <WinAPIEx.au3> ; Download From http://www.autoitscript.com/forum/topic/98712-winapiex-udf/ by Yashied. Local $hTimer = 0, $sFilePath = '' $hTimer = TimerInit() $sFilePath = _PathFull('.' & @ScriptName, @ScriptDir) $hTimer = TimerDiff($hTimer) ConsoleWrite('Original Path: ' & '.' & @ScriptName & @CRLF & _ 'Full Path: ' & $sFilePath & @CRLF & _ '_PathFull() Time: ' & $hTimer & @CRLF & @CRLF) $hTimer = TimerInit() $sFilePath = _PathFullEx('.' & @ScriptName, @ScriptDir) $hTimer = TimerDiff($hTimer) ConsoleWrite('Original Path: ' & '.' & @ScriptName & @CRLF & _ 'Full Path: ' & $sFilePath & @CRLF & _ '_PathFullEx() Time: ' & $hTimer & @CRLF & @CRLF) Func _PathFullEx($sRelativePath, $sBasePath = @WorkingDir) ; Created by guinness with the idea from _PathFull(). Local $sWorkingDir = @WorkingDir _WinAPI_SetCurrentDirectory($sBasePath) ; Same as using FileChangeDir(). Change the working directory of the current process to the base path as _WinAPI_GetFullPathName() merges the name of the current drive and directory with the specified file name. $sRelativePath = _WinAPI_GetFullPathName($sRelativePath) _WinAPI_SetCurrentDirectory($sWorkingDir) ; Reset the working directory to the previous path. Return $sRelativePath EndFunc ;==>_PathFullExAll of the above has been included in a ZIP file. _Path_ Functions (WinAPIEx).zip
×
×
  • Create New...