Jump to content

Recommended Posts

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Thanks. What were the changes you made?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Got it, thanks for that.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 6 months later...

just to give an example for Autoit v3.3.9.6 and after

; #FUNCTION# ====================================================================================================================
; Name...........: _PathSplitEx
; Description ...: Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing.
; Syntax.........: _PathSplitEx($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension)
; Parameters ....: $sFilePath  - The path to be split (Can contain a UNC server or drive letter)
;                 $sDrive    - String to hold the drive
;                 $sDir    - String to hold the directory
;                 $sFileName  - String to hold the file name
;                 $sExtension - String to hold the file extension
; Return values .: Success - Returns an array with 5 elements where 0 = original path 1 = drive, 2 = directory, 3 = filename, 4 = extension
; Author ........: DXRW4E
; Modified.......:
; Remarks .......: This function does not take a command line string. It works on paths, not paths with arguments.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _PathSplitEx($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension)
    $sFilePath = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1)
    $sDrive = $sFilePath[1]
    $sDir = StringRegExpReplace($sFilePath[2], "\h*[\/\\]+\h*", StringLeft($sFilePath[2], 1) == "/" ? "\/" : "\\")
    $sFileName = $sFilePath[3]
    $sExtension = $sFilePath[4]
    Return $sFilePath
EndFunc

Ciao a tutti.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

  • 2 weeks later...

You easily create this yourself by wrapping around _PathSplit and _PathSplitEx.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You easily create this yourself by wrapping around _PathSplit and _PathSplitEx.

 

Yes, and so can the next guy, and the next guy, and the next guy...

Makes you wonder why we have libraries at all ;)

Aren't there any convenience methods worth standardizing?

Link to comment
Share on other sites

Makes you wonder why we have libraries at all ;)

It makes me wonder why you just haven't created this yourself, instead of waiting for someone like me or DXRW4E to create it for you.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I do not understand what's wrong with the _PathSplit(), example

#include <Array.au3>
#include <File.au3>

Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit = _PathSplit("C:\some\darn\place\file.ext.ext2", $sDrive, $sDir, $sFilename, $sExtension)
_ArrayDisplay($aPathSplit, "_PathSplit of " & @ScriptFullPath)

;~ [0]|C:\some\darn\place\file.ext.ext2
;~ $sDrive = C:
;~ $sDir = \some\darn\place\
;~ $sFilename = file.ext
;~ $sExtension = .ext2

Local $p, $q, $d, $h, $n, $e, $f, $x, $r, $D2
;Local $sPart[10] = [$sDrive & $sDir, StringTrimLeft(StringTrimRight($sDir, 1), 1), StringTrimRight($sDrive & $sDir, 1), StringTrimRight(StringTrimLeft($sDir, StringInStr($sDir, "\", 1, -2)), 1), StringLeft($sFilename, StringInStr($sFilename, ".", 1) - 1), StringTrimLeft($sExtension, 1), $sFilename & $sExtension, StringTrimLeft($sFilename & $sExtension, StringInStr($sFilename & $sExtension, ".", 1, 1) - 1), $sDrive & "\", $sDrive]
;_ArrayDisplay($sPart)

$p = $sDrive & $sDir
$q = StringTrimLeft(StringTrimRight($sDir, 1), 1)
$d = StringTrimRight($p, 1)
$h = StringTrimLeft($d, StringInStr($d, "\", 1, -1))
$n = StringLeft($sFilename, StringInStr($sFilename, ".", 1) - 1)
$e = StringTrimLeft($sExtension, 1)
$f = $sFilename & $sExtension
$x = StringTrimLeft($f, StringInStr($f, ".", 1, 1) - 1)
$r = $sDrive & "\"
$D2 = $sDrive

ConsoleWrite($p & @LF & $q & @LF & $d & @LF & $h & @LF & $n & @LF & $e & @LF & $f & @LF & $x & @LF & $r & @LF & $D2 & @LF)

;~ >Running:(3.3.9.15):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script (Beta).au3"
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ C:\some\darn\place\
;~ some\darn\place
;~ C:\some\darn\place
;~ place
;~ file
;~ ext2
;~ file.ext.ext2
;~ .ext.ext2
;~ C:\
;~ C:
;~ +>00:34:31 AutoIt3.exe ended.rc:0
;~ >Exit code: 0    Time: 1.894

because it is impossible for the function to calculate each user's preference, some may want "C:aaabbbcccdddeee.ext.ext2.ext3" in

".ext.ext2.ext3"

".ext2"

"bbbcccddd"

"eee.ext.ext2"

ect ect

 

Ciao a tutti.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Nothing is wrong, it splits the filepath into what can only be describes as known segments. ROOT|FOLDER|FILENAME|EXTENSION.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

good

#include <Array.au3>
#include <File.au3>
#include <FileOperations.au3>

$aFileList = _FO_FileSearch(@WindowsDir)
; $aFileList = _FO_FileSearch('C:\Documents and Settings')
;========================================================

Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension)
    $aPathSplit1 = _PathSplit1($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension)
    For $j = 1 To 4
        If $aPathSplit[$j] <> $aPathSplit1[$j] Then MsgBox(0, 'Error', $aPathSplit[0] & @LF & @LF & $aPathSplit[$j] & @LF & @LF & $aPathSplit1[$j])
    Next
Next
MsgBox(0, 'Done', 'Done, files = ' & $aFileList[0])

;========================================================

Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit

$timer1 = TimerInit()
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit1($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
Next
$timer1 = Round(TimerDiff($timer1), 2)

$timer2 = TimerInit()
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.8.1
Next
$timer2 = Round(TimerDiff($timer2), 2)

MsgBox(0, "Done", _
        '$timer1 = ' & $timer1 & ' msec' & @LF & _
        '$timer2 = ' & $timer2 & ' msec')
;========================================================

Func _PathSplit1($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFilename, ByRef $sExtension)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1)
    If @error Then ; This error should never happen.
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    $tmp = StringLeft($aArray[2], 1) == "/"
    If $tmp Then
        $tmp = "\/"
    Else
        $tmp = "\\"
    EndIf
    $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", $tmp) ; StringRegExpReplace($aArray[2], "[\/\\]+\h*", "\" & ((StringLeft($aArray[2], 1) == "/") ? "/" : "\"))
    $sFilename = $aArray[3]
    $sExtension = $aArray[4]
    Return $aArray
EndFunc   ;==>_PathSplit1
Link to comment
Share on other sites

#include <Array.au3>
#include <File.au3>
#include <FileOperations.au3>

$aFileList = _FO_FileSearch(@WindowsDir)
; $aFileList = _FO_FileSearch('C:\Documents and Settings')
;========================================================

Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension)
    $aPathSplit1 = _PathSplit1($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension)
    For $j = 1 To 4
        If $aPathSplit[$j] <> $aPathSplit1[$j] Then MsgBox(0, 'Error', $aPathSplit[0] & @LF & @LF & $aPathSplit[$j] & @LF & @LF & $aPathSplit1[$j])
    Next
Next
MsgBox(0, 'Done', 'Done, files = ' & $aFileList[0])

;========================================================

Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit

$timer1 = TimerInit()
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit1($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
Next
$timer1 = Round(TimerDiff($timer1), 2)

$timer2 = TimerInit()
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
Next
$timer2 = Round(TimerDiff($timer2), 2)

ConsoleWrite("Done " & _
        '$timer1 = ' & $timer1 & ' msec' & @LF & _
        '$timer2 = ' & $timer2 & ' msec' & @LF)
;========================================================

Func _PathSplit1($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFilename, ByRef $sExtension)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1)
    If @error Then ; This error should never happen.
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    $tmp = StringLeft($aArray[2], 1) == "/"
    If $tmp Then
        $tmp = "\/"
    Else
        $tmp = "\\"
    EndIf
    $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", $tmp) ; StringRegExpReplace($aArray[2], "[\/\\]+\h*", "\" & ((StringLeft($aArray[2], 1) == "/") ? "/" : "\"))
    $sFilename = $aArray[3]
    $sExtension = $aArray[4]
    Return $aArray
EndFunc   ;==>_PathSplit1
;~ >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Users\DXRW4E\Desktop\FileOperations_En\New AutoIt v3 Script (Beta).au3" /UserParams    
;~ +>18:22:51 Starting AutoIt3Wrapper v.2.1.2.16    Environment(Language:0409  Keyboard:00000409  OS:WIN_8/  CPU:X64 OS:X64)
;~ >Running AU3Check (3.3.9.16)  from:C:\Program Files (x86)\AutoIt3\Beta
;~ +>18:22:51 AU3Check ended.rc:0
;~ >Running:(3.3.9.16):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\FileOperations_En\New AutoIt v3 Script (Beta).au3"    
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ Done $timer1 = 5574.09 msec
;~ $timer2 = 5075.09 msec
;~ +>18:23:17 AutoIt3.exe ended.rc:0
;~ >Exit code: 0    Time: 26.556

Hi AZJIO, who the point the speed ?, because _PathSplit is more faster ?

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

It works faster.

Func _PathSplit2($szPath, ByRef $szDrive, ByRef $szDir, ByRef $szFName, ByRef $szExt)
    Local $pos, $array[5] = [$szPath]
    Local $nPosForward = StringInStr($szPath, '/', 1, -1)
    Local $nPosBackward = StringInStr($szPath, '\', 1, -1)
    If $nPosForward >= $nPosBackward Then
        $pos = $nPosForward
    Else
        $pos = $nPosBackward
    EndIf
    $array[3] = StringTrimLeft($szPath, $pos) ; Имя с расширением
    $array[2] = StringLeft($szPath, $pos) ; Левая часть - путь к папке

    If StringMid($array[2], 2, 1) = ':' Then
        $array[1] = StringLeft($array[2], 2) ; drive
        $array[2] = StringTrimLeft($array[2], 2)
    ElseIf StringLeft($array[2], 2) = '\\' Then
        $array[2] = StringTrimLeft($array[2], 2) ; Trim the \\
        $pos = StringInStr($array[2], '\')
        If $pos = 0 Then $pos = StringInStr($array[2], '/')
        If $pos = 0 Then
            $array[1] = '\\' & $array[2]; Prepend the \\ we stripped earlier
            $array[2] = ''; Set to null because the whole path was just the UNC server name
        Else
            $pos -= 1
            $array[1] = '\\' & StringLeft($array[2], $pos) ; Prepend the \\ we stripped earlier
            $array[2] = StringTrimLeft($array[2], $pos)
        EndIf
    EndIf

    $pos = StringInStr($array[3], '.', 1, -1) ; Ищем справа "."
    If $pos Then ; Если имя содержит ".", то
        $pos -= 1
        $array[4] = StringTrimLeft($array[3], $pos) ; Отрезаем слева имя оставляя расширение
        $array[3] = StringLeft($array[3], $pos) ; Читаем слева имя до точки
    EndIf

    ; Set the strings and array to what we found
    $szDrive = $array[1]
    $szDir = $array[2]
    $szFName = $array[3]
    $szExt = $array[4]
    Return $array
EndFunc   ;==>_PathSplit
Link to comment
Share on other sites

_PathSplit is the best way, performs checks more secure, what's more it also repair the path, there are thousands of possible scenarios (which should normally never happen) it is not worth to name them all now, that the _PathSplit makes them more well, example

#include <Array.au3>
#include <File.au3>


Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit, $sPath = "C:\aaa//bbb\\\ccc.exe"


$aPathSplit = _PathSplit2($sPath, $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
_ArrayDisplay($aPathSplit)
ConsoleWrite('$sDrive = ' & $sDrive & @LF & _
        '$sDir = ' & $sDir & @LF & _
        '$sDir = ' & $sFilename & @LF & _
        '$sExtension = ' & $sExtension & @LF & @LF)

 $aPathSplit = _PathSplit($sPath, $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
_ArrayDisplay($aPathSplit)

ConsoleWrite('$sDrive = ' & $sDrive & @LF & _
        '$sDir = ' & $sDir & @LF & _
        '$sDir = ' & $sFilename & @LF & _
        '$sExtension = ' & $sExtension & @LF & @LF)

;========================================================

Func _PathSplit2($szPath, ByRef $szDrive, ByRef $szDir, ByRef $szFName, ByRef $szExt)
    Local $pos, $array[5] = [$szPath]
    Local $nPosForward = StringInStr($szPath, '/', 1, -1)
    Local $nPosBackward = StringInStr($szPath, '\', 1, -1)
    If $nPosForward >= $nPosBackward Then
        $pos = $nPosForward
    Else
        $pos = $nPosBackward
    EndIf
    $array[3] = StringTrimLeft($szPath, $pos) ; Имя с расширением
    $array[2] = StringLeft($szPath, $pos) ; Левая часть - путь к папке

    If StringMid($array[2], 2, 1) = ':' Then
        $array[1] = StringLeft($array[2], 2) ; drive
        $array[2] = StringTrimLeft($array[2], 2)
    ElseIf StringLeft($array[2], 2) = '\\' Then
        $array[2] = StringTrimLeft($array[2], 2) ; Trim the \\
        $pos = StringInStr($array[2], '\')
        If $pos = 0 Then $pos = StringInStr($array[2], '/')
        If $pos = 0 Then
            $array[1] = '\\' & $array[2]; Prepend the \\ we stripped earlier
            $array[2] = ''; Set to null because the whole path was just the UNC server name
        Else
            $pos -= 1
            $array[1] = '\\' & StringLeft($array[2], $pos) ; Prepend the \\ we stripped earlier
            $array[2] = StringTrimLeft($array[2], $pos)
        EndIf
    EndIf

    $pos = StringInStr($array[3], '.', 1, -1) ; Ищем справа "."
    If $pos Then ; Если имя содержит ".", то
        $pos -= 1
        $array[4] = StringTrimLeft($array[3], $pos) ; Отрезаем слева имя оставляя расширение
        $array[3] = StringLeft($array[3], $pos) ; Читаем слева имя до точки
    EndIf

    ; Set the strings and array to what we found
    $szDrive = $array[1]
    $szDir = $array[2]
    $szFName = $array[3]
    $szExt = $array[4]
    Return $array
EndFunc   ;==>_PathSplit
>Running:(3.3.9.16):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\New AutoIt v3 Script (Beta).au3"    
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ $sDrive = C:
;~ $sDir = \aaa//bbb\\\
;~ $sDir = ccc
;~ $sExtension = .exe

;~ $sDrive = C:
;~ $sDir = \aaa\bbb\
;~ $sDir = ccc
;~ $sExtension = .exe

so about the speed, if you takedisable in _PathSplit() the repair option, here

#include <Array.au3>
;#include <File.au3>
#include <FileOperations.au3>


$aFileList = _FO_FileSearch(@WindowsDir)
; $aFileList = _FO_FileSearch('C:\Documents and Settings')
;========================================================

Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension)
    $aPathSplit1 = _PathSplit1($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension)
    For $j = 1 To 4
        If $aPathSplit[$j] <> $aPathSplit1[$j] Then MsgBox(0, 'Error', $aPathSplit[0] & @LF & @LF & $aPathSplit[$j] & @LF & @LF & $aPathSplit1[$j])
    Next
Next
MsgBox(0, 'Done', 'Done, files = ' & $aFileList[0])

;========================================================

Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
Local $aPathSplit

$timer1 = TimerInit()
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit1($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
Next
$timer1 = Round(TimerDiff($timer1), 2)

$timer2 = TimerInit()
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit2($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
Next
$timer2 = Round(TimerDiff($timer2), 2)

$timer3 = TimerInit()
For $i = 1 To $aFileList[0]
    $aPathSplit = _PathSplit($aFileList[$i], $sDrive, $sDir, $sFilename, $sExtension) ; 3.3.9.16
Next
$timer3 = Round(TimerDiff($timer3), 2)


ConsoleWrite("Done " & _
        '$timer1 = ' & $timer1 & ' msec' & @LF & _
        '$timer2 = ' & $timer2 & ' msec' & @LF & _
        '$timer3 = ' & $timer3 & ' msec' & @LF)
;========================================================

; #FUNCTION# ====================================================================================================================
; Author ........: Valik
; Modified.......: DXRW4E - Re-wrote to use a regular expression; guinness - Update syntax and structure.
; ===============================================================================================================================
Func _PathSplit($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFileName, ByRef $sExtension)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1)
    If @error Then ; This error should never happen.
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    $sDir = $aArray[2]
    ;$sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", StringLeft($aArray[2], 1) == "/" ? "\/" : "\\") ; StringRegExpReplace($aArray[2], "[\/\\]+\h*", "\" & ((StringLeft($aArray[2], 1) == "/") ? "/" : "\"))
    $sFileName = $aArray[3]
    $sExtension = $aArray[4]
    Return $aArray
EndFunc   ;==>_PathSplit


Func _PathSplit1($sFilePath, ByRef $sDrive, ByRef $sDir, ByRef $sFilename, ByRef $sExtension)
    Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1)
    If @error Then ; This error should never happen.
        ReDim $aArray[5]
        $aArray[0] = $sFilePath
    EndIf
    $sDrive = $aArray[1]
    $tmp = StringLeft($aArray[2], 1) == "/"
    If $tmp Then
        $tmp = "\/"
    Else
        $tmp = "\\"
    EndIf
    $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", $tmp) ; StringRegExpReplace($aArray[2], "[\/\\]+\h*", "\" & ((StringLeft($aArray[2], 1) == "/") ? "/" : "\"))
    $sFilename = $aArray[3]
    $sExtension = $aArray[4]
    Return $aArray
EndFunc   ;==>_PathSplit1

Func _PathSplit2($szPath, ByRef $szDrive, ByRef $szDir, ByRef $szFName, ByRef $szExt)
    Local $pos, $array[5] = [$szPath]
    Local $nPosForward = StringInStr($szPath, '/', 1, -1)
    Local $nPosBackward = StringInStr($szPath, '\', 1, -1)
    If $nPosForward >= $nPosBackward Then
        $pos = $nPosForward
    Else
        $pos = $nPosBackward
    EndIf
    $array[3] = StringTrimLeft($szPath, $pos) ; Имя с расширением
    $array[2] = StringLeft($szPath, $pos) ; Левая часть - путь к папке

    If StringMid($array[2], 2, 1) = ':' Then
        $array[1] = StringLeft($array[2], 2) ; drive
        $array[2] = StringTrimLeft($array[2], 2)
    ElseIf StringLeft($array[2], 2) = '\\' Then
        $array[2] = StringTrimLeft($array[2], 2) ; Trim the \\
        $pos = StringInStr($array[2], '\')
        If $pos = 0 Then $pos = StringInStr($array[2], '/')
        If $pos = 0 Then
            $array[1] = '\\' & $array[2]; Prepend the \\ we stripped earlier
            $array[2] = ''; Set to null because the whole path was just the UNC server name
        Else
            $pos -= 1
            $array[1] = '\\' & StringLeft($array[2], $pos) ; Prepend the \\ we stripped earlier
            $array[2] = StringTrimLeft($array[2], $pos)
        EndIf
    EndIf

    $pos = StringInStr($array[3], '.', 1, -1) ; Ищем справа "."
    If $pos Then ; Если имя содержит ".", то
        $pos -= 1
        $array[4] = StringTrimLeft($array[3], $pos) ; Отрезаем слева имя оставляя расширение
        $array[3] = StringLeft($array[3], $pos) ; Читаем слева имя до точки
    EndIf

    ; Set the strings and array to what we found
    $szDrive = $array[1]
    $szDir = $array[2]
    $szFName = $array[3]
    $szExt = $array[4]
    Return $array
EndFunc   ;==>_PathSplit
;~ >"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /beta /ErrorStdOut /in "C:\Users\DXRW4E\Desktop\FileOperations\FileOperations_En\New AutoIt v3 Script (Beta).au3" /UserParams    
;~ +>00:19:20 Starting AutoIt3Wrapper v.2.1.2.16    Environment(Language:0409  Keyboard:00000409  OS:WIN_8/  CPU:X64 OS:X64)
;~ >Running AU3Check (3.3.9.16)  from:C:\Program Files (x86)\AutoIt3\Beta
;~ +>00:19:20 AU3Check ended.rc:0
;~ >Running:(3.3.9.16):C:\Program Files (x86)\AutoIt3\Beta\autoit3.exe "C:\Users\DXRW4E\Desktop\FileOperations\FileOperations_En\New AutoIt v3 Script (Beta).au3"    
;~ --> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
;~ Done $timer1 = 5333.88 msec
;~ $timer2 = 4394.69 msec
;~ $timer3 = 3362.21 msec
;~ +>00:19:48 AutoIt3.exe ended.rc:0
;~ >Exit code: 0    Time: 28.779

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Because it did not cost anything as you can see _PathSplit is only 7 line, however is only _PathSplit() everything else about Path (how to say in an Microsoft official way) is in AutoIt help WinApiEx ShellPath Management (#include <WinAPIShPath.au3>.)

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

A year ago, when I tested _FO_PathSplit, then the regular expression was slower than the string functions. But I returned the 3 elements (380 msec). Apparently the number of elements affect the speed of regular expressions

Because it did not cost anything

You consider, what 30% it anything? 980 -> 650
If this is the correct path to the file, it returns correctly. If this is not the correct path to the file, whether the user wanted to correct it?

Edited by AZJIO
Link to comment
Share on other sites

to check if the path is correct and repair the path it costs the same time ehhh, so better to perform the repair directly, StringRegExp always return ok, so why not take the opportunity to repair the path ;)

as mentioned before are things that normally should not happen ever, but if I'm not mistaken many Windows Api and AutoIt native function (FileExists and FileRead ect ect), perform repair of the path before proceeding ect ect, so how to say is not out of place that _PathSplit try to repair the path, I think it's better this way because being a function which is the default is better to take all precautions, however it remains a choice hmmm I do not know

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...