AntiVirusGuy Posted April 3, 2009 Posted April 3, 2009 (edited) Apparently I am not smart enough to use _PathSplit so I made this simple function expandcollapse popup;#FUNCTION# ==================================================================================================== ================ ; Name...........: _SBfpsplit ; Description ...: Splits a file path into Drive, path, filename, or extension. ; Syntax.........: _SBfpsplit($SBPath, $SBType);$SBpath (file path to evaluate) , $SBType (option) ; Parameters ....: ;|1 = Drive ex. D: ;|2 = Path ex. D:\1111\dir\file.txt ;|3 = File name ex. file.txt ;|4 = Extension ex. txt ;|5 = Drive letter only ex. D ; Author ........: Scott E. Brown ripandreplace@eset.com ; Modified.......:04/03/2009 ; Remarks .......: ; Related .......: ; Link ..........; ; Example .......; _SBfpsplit("D:\1111\dir\file.txt, 1) ; ;$path = "D:\1111\dir\test.txt" ;ConsoleWrite(_SBfpsplit($path, 1) & @CRLF) ;ConsoleWrite(_SBfpsplit($path, 2) & @CRLF) ;ConsoleWrite(_SBfpsplit($path, 3) & @CRLF) ;ConsoleWrite(_SBfpsplit($path, 5) & @CRLF) ; ==================================================================================================== =========================== Func _SBfpsplit($SBPath, $SBType);$SBpath = file path to evaluate , $SBType = 1 for Drive, 2 for Path, 3 for File name, 4 for extension, 5 for drive letter only Local $SBfile, $SBSplit, $SBdrive, $SBfilepath, $SBnumber $SBSplit = StringSplit($SBPath, "\"); split into array $SBnumber = $SBSplit[0]; the number of strings returned $SBfilepath = "" for $1 = 1 to $SBnumber -1 $SBfilepath = $SBfilepath & $SBSplit[$1] & "\"; path Next $SBfile = $SBSplit[($SBsplit[0])]; file $SBdrive = $SBSplit[1]; drive $SBfs = StringSplit($SBPath, "."); split into array ;MsgBox(4096, "Path", $SBSfs[0]) if $SBfs[0] = 1 then $SBExt = ""; no extension found Else $SBExt = $SBfs[($SBfs[0])]; last . extentsion EndIf If $SBType = 1 then Return $SBdrive If $SBType = 2 then Return $SBfilepath If $SBType = 3 then Return $SBfile If $SBType = 4 then Return $SBExt If $SBType = 5 then Return StringLeft($SBdrive, 1) EndFuncfile_path_include.au3 Edited April 3, 2009 by ssebrownatcolby
ReCoder Posted April 7, 2009 Posted April 7, 2009 Nice work. But you can create a wrapper for _PathSplit(...) (include <File.au3>) like this ... #cs String _GetFilename(<FullPath+Filename>) returns the filename without extension from full path used include <File.au3> used func _PathSplit(...) #ce func _GetFilename($psFilename) local $szDrive, $szDir, $szFName, $szExt _PathSplit($psFilename, $szDrive, $szDir, $szFName, $szExt) return $szFName EndFunc #cs String _GetExtension(<FullPath+Filename>) returns the extension from filename used include <File.au3> used func _PathSplit(...) #ce func _GetExtension($psFilename) local $szDrive, $szDir, $szFName, $szExt _PathSplit($psFilename, $szDrive, $szDir, $szFName, $szExt) return $szExt EndFunc #cs String _GetDirname(<FullPath+Filename>) returns the drive+directory from full path used include <File.au3> used func _PathSplit(...) #ce func _GetDirname($psFilename) local $szDrive, $szDir, $szFName, $szExt _PathSplit($psFilename, $szDrive, $szDir, $szFName, $szExt) return $szDrive & $szDir EndFunc
nobbe Posted April 7, 2009 Posted April 7, 2009 (edited) after all its not so complicated? after the function call PathSplit "ALL" parameter are already filled (byref) #include <File.au3> local $szDrive, $szDir, $szFName, $szExt $full = "c:\dir1\dir2\test.wav" _PathSplit($full, $szDrive, $szDir, $szFName, $szExt) ; after the function call "ALL" parameter are already filled MsgBox(0, $full, "Drive = "& $szDrive & @crlf & "Dir = "& $szDir & @crlf & "Filename = "& $szFName & @crlf & "Extension = "& $szExt); exit Edited April 7, 2009 by nobbe
AntiVirusGuy Posted May 17, 2009 Author Posted May 17, 2009 after all its not so complicated? after the function call PathSplit "ALL" parameter are already filled (byref) #include <File.au3> local $szDrive, $szDir, $szFName, $szExt $full = "c:\dir1\dir2\test.wav" _PathSplit($full, $szDrive, $szDir, $szFName, $szExt) ; after the function call "ALL" parameter are already filled MsgBox(0, $full, "Drive = "& $szDrive & @crlf & "Dir = "& $szDir & @crlf & "Filename = "& $szFName & @crlf & "Extension = "& $szExt); exit I didn't understand what byref meant but a coworker explained it. So now I get how it works blond moment I guess.
HardXOR Posted August 27, 2015 Posted August 27, 2015 $timer = TimerInit() Local $P_drive, $P_dir, $P_filename, $P_ext _PathSplit($FilePath, $P_drive, $P_dir, $P_filename, $P_ext) MsgBox(0, "", TimerDiff($timer))this took on my machine 0.09 - 0.11 ms$timer = TimerInit() $Filename = StringRegExp($FilePath, '.*\\(.*)', 1) MsgBox(0, "", TimerDiff($timer))and this code took 0.01 - 0.02 msi know its ms, but still like faster code, especially for files... noone knows if you want use it thousands or milions times, and 10x faster code is quite usefull
iamtheky Posted August 27, 2015 Posted August 27, 2015 (edited) same speed increase getting filename without regexp, just for sportstringright($FilePath , StringLen($FilePath) - StringInStr($FilePath , "\" , 0, -1))and then dir, naturallystringleft($FilePath , StringInStr($FilePath , "\" , 0, -1))and extstringright($FilePath , StringLen($FilePath) - StringInStr($FilePath , "." , 0, -1)) Edited August 27, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
JohnOne Posted August 27, 2015 Posted August 27, 2015 Drive for fun.StringSplit($FilePathath, "\", 2)[0] AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans.
jchd Posted August 27, 2015 Posted August 27, 2015 HardXOR,Resurrecting a 6-year old thread for cutting milliseconds is indeed something. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
iamtheky Posted August 28, 2015 Posted August 28, 2015 egad, necromancer gets me again! ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
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