Borje 0 Posted June 7, 2016 Hello anybody! I want to ask if anybody user here that can help me little and can give me some tips how to find a file extension Example if I have a file: TESTING.EXE how to find out the exe or .exe for that file what code i must have to find that. Share this post Link to post Share on other sites
VIP 26 Posted June 7, 2016 Use _PathSplit() ! Or my function: Func _SplitPath($sFilePath, $sType = 0) Local $sDrive, $sDir, $sFileName, $sExtension, $sReturn Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) If @error Then ReDim $aArray[5] $aArray[0] = $sFilePath EndIf $sDrive = $aArray[1] If StringLeft($aArray[2], 1) == "/" Then $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/") Else $sDir = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\") EndIf $aArray[2] = $sDir $sFileName = $aArray[3] $sExtension = $aArray[4] If $sType = 1 Then Return $sDrive If $sType = 2 Then Return $sDir If $sType = 3 Then Return $sFileName If $sType = 4 Then Return $sExtension If $sType = 5 Then Return $sFileName & $sExtension If $sType = 6 Then Return $sDrive & $sDir If $sType = 7 Then Return $sDrive & $sDir & $sFileName Return $aArray EndFunc ;==>_SplitPath Regards, Share this post Link to post Share on other sites
Borje 0 Posted June 7, 2016 Thanks Trong for this example but I can not have that to work can you explain how you insert a file to this, example: file TEST.EXE and then pick upp $sExtension Share this post Link to post Share on other sites
Danyfirex 539 Posted June 7, 2016 Hello. Just for fun MsgBox(0, "", _GetExtension("test.test.exe")) MsgBox(0, "", _GetExtension("test.xml")) MsgBox(0, "", _GetExtension("test")) MsgBox(0, "", _GetExtension("test.name.test.temp")) Func _GetExtension($sName) Return StringMid($sName, StringInStr($sName, ".", 0, -1)) EndFunc ;==>_GetExtension Saludos 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Share this post Link to post Share on other sites
VIP 26 Posted June 7, 2016 (edited) 1 hour ago, Borje said: Thanks Trong for this example but I can not have that to work can you explain how you insert a file to this, example: file TEST.EXE and then pick upp $sExtension @Danyfirex Trong consider add something like this Global Enum $eDrive=1, $eDir, $eFileName, $eExtension, $eFullFileName, $ePath, $ePathNoEXT expandcollapse popupGlobal Enum $eDrive = 1, $eDir, $eFileName, $eExtension, $eFullFileName, $ePath, $ePathNoEXT Global $sPathSplit = _SplitPath(@ScriptFullPath) ConsoleWrite("+ Path IN: " & $sPathSplit[0] & @CRLF) ConsoleWrite("- Drive: " & $sPathSplit[1] & @CRLF) ConsoleWrite("- Dir: " & $sPathSplit[2] & @CRLF) ConsoleWrite("- FileName: " & $sPathSplit[3] & @CRLF) ConsoleWrite("- Extension: " & $sPathSplit[4] & @CRLF) ConsoleWrite("- FullFileName: " & $sPathSplit[5] & @CRLF) ConsoleWrite("- Path: " & $sPathSplit[6] & @CRLF) ConsoleWrite("- PathNoEXT: " & $sPathSplit[7] & @CRLF) Global $sPathSplit = @SystemDir & "\cmd.exe" ConsoleWrite("! Path IN: " & $sPathSplit & @CRLF) ConsoleWrite("- Drive: " & _SplitPath($sPathSplit, $eDrive) & @CRLF) ConsoleWrite("- Dir: " & _SplitPath($sPathSplit, $eDir) & @CRLF) ConsoleWrite("- FileName: " & _SplitPath($sPathSplit, $eFileName) & @CRLF) ConsoleWrite("- Extension: " & _SplitPath($sPathSplit, $eExtension) & @CRLF) ConsoleWrite("- FullFileName: " & _SplitPath($sPathSplit, $eFullFileName) & @CRLF) ConsoleWrite("- Path: " & _SplitPath($sPathSplit, $ePath) & @CRLF) ConsoleWrite("- PathNoEXT: " & _SplitPath($sPathSplit, $ePathNoEXT) & @CRLF) Func _SplitPath($sFilePath, $rType = 0) Local $aArray = StringRegExp($sFilePath, "^\h*((?:\\\\\?\\)*(\\\\[^\?\/\\]+|[A-Za-z]:)?(.*[\/\\]\h*)?((?:[^\.\/\\]|(?(?=\.[^\/\\]*\.)\.))*)?([^\/\\]*))$", 1) Local $rError = @error ReDim $aArray[8] If $rError Then $aArray[0] = $sFilePath ; Original path If StringLeft($aArray[2], 1) == "/" Then $aArray[2] = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\/") Else $aArray[2] = StringRegExpReplace($aArray[2], "\h*[\/\\]+\h*", "\\") EndIf $aArray[5] = $aArray[3] & $aArray[4] $aArray[6] = $aArray[1] & $aArray[2] $aArray[7] = $aArray[6] & $aArray[3] If $rType = 1 Then Return $aArray[1] ; Drive If $rType = 2 Then Return $aArray[2] ; Dir If $rType = 3 Then Return $aArray[3] ; FileName If $rType = 4 Then Return $aArray[4] ; Extension If $rType = 5 Then Return $aArray[5] ; FullFileName : FileName & $eExtension If $rType = 6 Then Return $aArray[6] ; Path : Drive & $eDir If $rType = 7 Then Return $aArray[7] ; PathNoEXT : Drive & Dir & FileName Return $aArray ; Array with 8 elements EndFunc ;==>_SplitPath Edited June 7, 2016 by Trong Regards, Share this post Link to post Share on other sites
Borje 0 Posted June 7, 2016 Thanks very very much Trong now I have this to work I have much to learn. Share this post Link to post Share on other sites
Danyfirex 539 Posted June 7, 2016 @Trong consider add something like this Global Enum $eDrive=1,$eDir,$eFileName,$eExtension,$eFullFileName,$ePath,$ePathNoEXT Saludos 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Share this post Link to post Share on other sites
Borje 0 Posted June 7, 2016 Hi Danyfirex Thank you very much for your example that works perfect your little example is was I need thanks again. Have a nice day !! Share this post Link to post Share on other sites