Champak Posted December 6, 2021 Share Posted December 6, 2021 I have a terrible relationship with this function, so looking for some assistance please. I need 4 codes. 1/ I have this, but it is unnecessarily complicated, and I believe it could be done easier and faster if a regexp function can be put inside an _ArraySearch function fo look for a numeric value greater than 0. $u += 1 If $u = 15 Then For $u = 0 to UBound($aDiskLoad) - 1 If $aDiskLoad[$u] > 0 Then $sDiskLoad = False EndIf Next EndIf 2/ I have this, but it doesn't seem to be working right. Global $sAcceptedFiles = ".jpg|.mp4" ;If the file is anything except mp4, jpg skip and continue loop If Not StringRegExp($sExtension, "\b(" & $sAcceptedFiles & ")\b") Then ConsoleWrite(@CRLF & "> Invalid File Type." & @CRLF) ContinueLoop EndIf 3/ I have an array with a file list and need to extract any file that doesn't have a specific file name format of "YYYY-MM-DD_HHMMSS_P" (That "P" could also be a "V") and a file extension. 4/ The last one is not coming to my mind right now....I'll have to come back to this one. Thanks. Link to comment Share on other sites More sharing options...
jguinch Posted December 6, 2021 Share Posted December 6, 2021 1 If _ArraySearch($aDiskLoad) <> -1 Then $sDiskLoad = False 2 Global $sAcceptedFiles = ".jpg|.mp4" ;If the file is anything except mp4, jpg skip and continue loop If Not StringRegExp($sExtension, StringReplace($sAcceptedFiles, ".", "\.") & "$" Then ConsoleWrite(@CRLF & "> Invalid File Type." & @CRLF) ContinueLoop EndIf 3 If Not StringRegExp($string, "^\d{4}(-\d{2}){2}_\d{6}_[PV]$") Then ConsoleWrite("error") Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Champak Posted December 6, 2021 Author Share Posted December 6, 2021 (edited) Thanks for 2 and 3, I'll see how they work out when I get home. But I don't understand how what you are doing with 1. As far as 2 is concerned with my original version, is it not working because I have the "." in the extensions? Edit: 2 seems to be case sensitive, how do i make it none sensitive? Edited December 7, 2021 by Champak Link to comment Share on other sites More sharing options...
Champak Posted December 7, 2021 Author Share Posted December 7, 2021 This isn't working for me as I want it to. If I feed an array directly to it, no issue. But if I do it from the file open dialogue it doesn't see the files it should match. I tried stripping WS and CR and put the quotes around the variable just to make sure. I don't see what could be the issue. $FileSelect = FileOpenDialog("File Rename", "F:\", "Images (*.jpg)|Videos (*.mp4)", $FD_MULTISELECT, "", $hForm) $aDirContent_New = StringSplit($sFileSelect, "|", 2) _ArrayDisplay($aDirContent_New) For $i = UBound($aDirContent_New) - 1 To 0 Step - 1 ConsoleWrite($i & "'" & $aDirContent_New[$i] & "'" & @CRLF) If StringRegExp($aDirContent_New[$i], "^\d{4}(-\d{2}){2}_\d{6}_[PV]$") Then ConsoleWrite("> " & $i & @CRLF) _ArrayDelete($aDirContent_New, $i) ContinueLoop EndIf ;$aDirContent_New[$i] = $aDirContent_New[0] & "\" & $aDirContent_New[$i] Next _ArrayDisplay($aDirContent_New) Note: I took out the "Not" because I was just testing some things. Link to comment Share on other sites More sharing options...
mikell Posted December 7, 2021 Share Posted December 7, 2021 Please try after correcting the typo $FileSelect = FileOpenDialog(.... $aDirContent_New = StringSplit($sFileSelect, ... Link to comment Share on other sites More sharing options...
ad777 Posted December 7, 2021 Share Posted December 7, 2021 (edited) maybe this help's: #include <File.au3> #include <WinAPISysWin.au3> Global $GText Local $hTimerProc = DllCallbackRegister('_TimerProc', 'none', 'hwnd;uint;uint_ptr;dword') Global $g_iCount = 0 Local $iTimerID = _WinAPI_SetTimer(0, 0, 1000, DllCallbackGetPtr($hTimerProc)) $title = "File Rename" $sFileSelect = FileOpenDialog($title, "F:\", "Images (*.jpg)|Videos (*.mp4)", $FD_MULTISELECT, "", 0) $aDirContent_New = StringSplit($GText, "''", 2) _ArrayDisplay($aDirContent_New) For $i = UBound($aDirContent_New) - 1 To 0 Step - 1 ConsoleWrite($i & "'" & $aDirContent_New[$i] & "'" & @CRLF) If StringRegExp($aDirContent_New[$i], "^\d{4}(-\d{2}){2}_\d{6}_[PV]$") Then ConsoleWrite("> " & $i & @CRLF) _ArrayDelete($aDirContent_New, $i) ContinueLoop EndIf ;$aDirContent_New[$i] = $aDirContent_New[0] & "\" & $aDirContent_New[$i] Next _ArrayDisplay($aDirContent_New) Func _TimerProc($hWnd, $iMsg, $iTimerID, $iTime) $GText = ControlGetText($title, "", "Edit1") EndFunc ;==>_TimerProc Edited December 7, 2021 by ad777 Champak 1 iam ِAutoit programmer. best thing in life is to use your Brain to Achieve everything you want. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 7, 2021 Moderators Share Posted December 7, 2021 ad777, When you reply in future, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily. Thanks in advance for your cooperation. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Champak Posted December 7, 2021 Author Share Posted December 7, 2021 @mikell That wasn't a typo, it was being passed through a function. @ad777 Thanks, that worked, just had to change: $aDirContent_New = StringSplit($GText, """", 2) If StringRegExp($aDirContent_New[$i], "^\d{4}(-\d{2}){2}_\d{6}_[PV]$") Or $aDirContent_New[$i] = " " Then So is this a bug with FileOpenDialog or is it known issue that can't be fixed? Link to comment Share on other sites More sharing options...
Developers Jos Posted December 8, 2021 Developers Share Posted December 8, 2021 (edited) Please start by posting a proper replication script showing your issue with some debug output before creating a bug report. I see a lot of "it doesn't work" but have no idea what the real issue is, so start adding debugging to show the EXACT strings being returned in the different cases. Bug report will be closed until there is a proper case to make for a dug. Jos Edited December 8, 2021 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
mikell Posted December 8, 2021 Share Posted December 8, 2021 @Champak I said this because using the provided script, with : - typo corrected - file extension included in the regex then for me it works (the following is runnable) #Include <Array.au3> #include <FileConstants.au3> $sFileSelect = FileOpenDialog("File Rename", @desktopdir & "\", "Images (*.jpg)|Videos (*.mp4)", $FD_MULTISELECT, "") $aDirContent_New = StringSplit($sFileSelect, "|", 2) _ArrayDisplay($aDirContent_New) For $i = UBound($aDirContent_New) - 1 To 0 Step - 1 ConsoleWrite($i & "'" & $aDirContent_New[$i] & "'" & @CRLF) If StringRegExp($aDirContent_New[$i], "^\d{4}(-\d{2}){2}_\d{6}_[PV]\.(?:jpg|mp4)$") Then ConsoleWrite("> " & $i & @CRLF) _ArrayDelete($aDirContent_New, $i) ContinueLoop EndIf ;$aDirContent_New[$i] = $aDirContent_New[0] & "\" & $aDirContent_New[$i] Next _ArrayDisplay($aDirContent_New) Link to comment Share on other sites More sharing options...
junkew Posted December 13, 2021 Share Posted December 13, 2021 Different approach No UI Using 2 cmd process runs to get a certain list of extensions (1 per run) Build the output based on whats found with regex (using consolewrite) Create the array with all files ending on jpg or mp4 expandcollapse popup#include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> ; Required for _ArrayDisplay only. ; Recursively display a list of files in a directory. Example() Func Example() Local $sFilePath = @ScriptDir ; Search the current script directory. Local $sFilter[2] = ["*.jpg","*.mp4"] Local $iPid[2], $sOut[2] ; If the file path isn't a directory then return from the 'Example' function. If Not StringInStr(FileGetAttrib($sFilePath), "D") Then Return SetError(1, 0, 0) EndIf ; Remove trailing backslashes and append a single trailing backslash. $sFilePath = StringRegExpReplace($sFilePath, "[\\/]+\z", "") & "\" #cs Commandline parameters for DIR: /B - Simple output. /A-D - Search for all files, minus folders. /S - Search within subfolders. #ce $iPID[0] = Run(@ComSpec & ' /C DIR "' & $sFilePath & $sFilter[0] & '" /B /A-D /S', $sFilePath, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD) $iPID[1] = Run(@ComSpec & ' /C DIR "' & $sFilePath & $sFilter[1] & '" /B /A-D /S', $sFilePath, @SW_HIDE, $STDOUT_CHILD + $STDERR_CHILD) ; If you want to search with files that contains unicode characters, then use the /U commandline parameter. ; Wait until the process has closed using the PID returned by Run. local $retVal=ProcessWaitClose($iPID[1]) $retVal=ProcessWaitClose($iPID[0]) ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead. $sOut[0] = StdoutRead($iPID[0]) $sOut[1] = StdoutRead($iPID[1]) & @CRLF ;Output as 1 string local $sOutput=$sOut[0] & $sOut[1] ;consolewrite($sOutput) Local $aArray = StringRegExp($sOutput, '(\d{4}-\d{2}-\d{2}_\d{6}_[PV]\..{3})',$STR_REGEXPARRAYGLOBALMATCH) For $i = 0 To UBound($aArray) - 1 consolewrite($i & " : " & $aArray[$i] & @CRLF) Next ; Use StringSplit to split the output of StdoutRead to an array. All carriage returns (@CR) are stripped and @CRLF (line feed) is used as the delimiter. Local $aArray = StringSplit(stringstripws($sOutput, $STR_STRIPTRAILING ), @crLF,$STR_ENTIRESPLIT) If @error Then MsgBox($MB_SYSTEMMODAL, "", "It appears there was an error trying to find all the files in the current script directory.") Else ; Display the results. _ArrayDisplay($aArray) EndIf EndFunc ;==>Example FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Bert Posted December 14, 2021 Share Posted December 14, 2021 Have you ever tried the Regex GUI script (Its a button) that is at the bottom of the Regex tutorial in the help file? It is a regex tester and it works quite well. Look for StringRegExpGUI.au3 The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
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