Achilles Posted July 24, 2008 Posted July 24, 2008 Hello, I was wondering if you're given a full path, what is the fastest/most efficient way to get the file name. I came up with this: $path = @ScriptFullPath Msgbox(0, '', _GetFileName($path)) Func _GetFileName($path) $temp = StringSplit($path, '\') Return $temp[$temp[0]] EndFunc My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
smashly Posted July 24, 2008 Posted July 24, 2008 Hi, $sPath = @AutoItExe ConsoleWrite(StringMid($sPath, StringInStr($sPath, "\", 0, -1) + 1) & @LF)
gumbitha Posted July 24, 2008 Posted July 24, 2008 $PathArray = StringSplit($InputPath, "\") $Filename = $PathArray[$PathArray[0]] muttley
crzftx Posted July 24, 2008 Posted July 24, 2008 (edited) I ran the following to find out the bottom method is about 25% faster. The top method takes about 12.79µs and the bottom method takes about 9.53µs; neither is going to hurt your execution time muttley My method (I'm calling the bottom one mine...) takes up half the lines though. Global Const $path = "C:\Windows\System32\Boot\en-US\winload.exe.mui", $amount = 200000 Global $timer, $array $timer = TimerInit() For $z = 0 To $amount $array = StringSplit($path, "\") $filename = $array[$array[0]] Next ConsoleWrite(Round(TimerDiff($timer)/$amount*1000,2) & "µs average" & @CRLF) $timer = TimerInit() For $z = 0 To $amount $filename = StringTrimLeft($path,StringInStr($path,"\",0,-1)) Next ConsoleWrite(Round(TimerDiff($timer)/$amount*1000,2) & "µs average" & @CRLF) Edited July 24, 2008 by crzftx
weaponx Posted July 24, 2008 Posted July 24, 2008 Global Const $path = "C:\Windows\System32\Boot\en-US\winload.exe.mui", $amount = 200000 Global $timer, $array ;STRINGSPLIT $Timer1 = TimerInit() For $z = 0 To $amount $array = StringSplit($path, "\") $filename = $array[$array[0]] Next ConsoleWrite(Round(TimerDiff($Timer1)/$amount*1000,2) & "µs average" & @CRLF) ;STRINGTRIMLEFT + STRINGINSTR $Timer2 = TimerInit() For $z = 0 To $amount $filename = StringTrimLeft($path,StringInStr($path,"\",0,-1)) Next ConsoleWrite(Round(TimerDiff($Timer2)/$amount*1000,2) & "µs average" & @CRLF) ;STRINGREGEXPREPLACE $Timer3 = TimerInit() For $z = 0 To $amount $filename = StringRegExpReplace($path, "^.*\\", "") Next ConsoleWrite(Round(TimerDiff($Timer3)/$amount*1000,2) & "µs average" & @CRLF) 11.94µs average 6.74µs average 8.45µs average
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now