ur Posted October 12, 2020 Share Posted October 12, 2020 I have below code to check for particular set of files. For that I am using the function _FileListToArrayRec Which has filter to check for particular file or with wildcard. So, the code is written to call three times. Instead, is there any filter you can suggest, instead of calling the search for 3 times like below. #include-once #include <Array.au3> #include <Date.au3> #include <file.au3> #include <FileConstants.au3> #include <WinAPIFiles.au3> Func LogData($sMessage,$sLogFile=@ScriptDir&"\Logging.log") If $sMessage = "" Then FileWriteLine($sLogFile, "") Else FileWrite($sLogFile,_NowCalc() & " :: " & $sMessage&@CRLF) EndIf EndFunc Func DeleteFiles($sFilter) Local $hFilesFolders = _FileListToArrayRec("C:", $sFilter,$FLTAR_FILES, $FLTAR_RECUR) _ArrayDisplay($hFilesFolders) For $i=0 to $hFilesFolders[0] Local $iReturn = FileDelete($hFilesFolders[$i]) LogData("Ran delete for : "& $hFilesFolders[$i] &" with error code: "&$iReturn) Next EndFunc DeleteFiles("*.au3") DeleteFiles("*.txt") Link to comment Share on other sites More sharing options...
jguinch Posted October 12, 2020 Share Posted October 12, 2020 DeleteFiles("*.au3;*.txt") Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 Thank you. Is there any option for Killing a process also by providing range of names like this? Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 15 minutes ago, ur said: Is there any option for Killing a process also by providing range of names like this? What do you think the answer is? 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...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 (edited) I thought to keep a function separately to call ProcessClose inside it. And split the input string at ; semicolon. And call the processclose one by one. But, the complete process name should be passed to it.It is not accepting wilcards. Is there any function someone already posted that supports wildcards? Got this, But is there any more simpler one? Edited October 12, 2020 by ur Link to comment Share on other sites More sharing options...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 Func ProcessCloseList() Local $list = ProcessList() For $i = 1 To $list[0][0] If StringRegExp($list[$i][0], "^note.*$;^wordpad.*$") Then ProcessClose($list[$i][0]) ;If StringRegExp($list[$i][0], "^" & $sString & "\d+\.exe$") Then ProcessClose($list[$i][0]) Next EndFunc "^note.*$;^wordpad.*$" I tried multiple patterns with ; but it doesn't work Link to comment Share on other sites More sharing options...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 Below code I tried but not closing the multiple notepads and wordpads. Func ProcessCloseList($sProcessList) Local $aProcess = StringSplit($sProcessList, ";") Local $list = ProcessList() For $j = 1 To $aProcess[0] Local $i = 1 For $i = 1 To $list[0][0] Local $temp = "^"& $aProcess[$j] &".*$" ConsoleWrite($aProcess[$j]&" - "&$temp&@CRLF) If StringRegExp($list[$i][0], $temp) Then ConsoleWrite("Trying to close process with ID: "& $list[$i][0]) Local $preturn = ProcessClose($list[$i][0]) ConsoleWrite(" - "&$preturn & " - "&@error) EndIf Next Next EndFunc ProcessCloseList("wordpad;notepad") Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 .. ok .. I see you are getting somewhere. So what is the problem you think? Are you getting any matches and is it actually trying to close a process? Maybe add some error/returncode checking in your code so you know why it is failing? 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...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 The "@error" value is 3 3 = TerminateProcess Failed No details other than that. But with windows taskkill command the process is closed. Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 So what does the helpfile tell you about getting more information? 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...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 by the way.... your posted script works fine on Notepad ....so what is it you are not telling us and makes your case different? 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...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 Single process it is working fine. If I launch like 5 notepad.exe then it is closing 1/2 in them Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 So try closing them by their PID in stead of Name since then your are closing a unique process! 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...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 ok, but present I used taskkill directly. RunWait(@SystemDir&"\taskkill.exe /f /im "&$list[$i][0]) Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 Again: Have you tried using the PID in stead of process name with ProcessClose()? Quote Remarks The array returned is two-dimensional and is made up as follows: $aArray[0][0] = Number of processes $aArray[1][0] = 1st Process name $aArray[1][1] = 1st Process ID (PID) $aArray[2][0] = 2nd Process name $aArray[2][1] = 2nd Process ID (PID) 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...
ur Posted October 12, 2020 Author Share Posted October 12, 2020 Hi, yes with process ID it is terminating. Func ProcessCloseList($sProcessList) Local $aProcess = StringSplit($sProcessList, ";") Local $list = ProcessList() For $j = 1 To $aProcess[0] Local $i = 1 For $i = 1 To $list[0][0] Local $temp = "^"& $aProcess[$j] &".*$" If StringRegExp($list[$i][0], $temp) Then ConsoleWrite("Trying to close process with ID: "& $list[$i][1]);0 for name of process Local $preturn = ProcessClose($list[$i][1]) ;Local $preturn=RunWait(@SystemDir&"\taskkill.exe /f /im "&$list[$i][0]) ConsoleWrite(" - "&$preturn & " - "&@error&" - "&@extended) EndIf Next Next EndFunc ProcessCloseList("wordpad;notepad") Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 Just now, ur said: Hi, yes with process ID it is terminating. Which makes a lot of sense ...right? JockoDundee 1 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...
JockoDundee Posted October 12, 2020 Share Posted October 12, 2020 Extra Credit: Will this script kill all instances of notepad.exe? While ProcessClose("notepad.exe") WEnd Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Developers Jos Posted October 12, 2020 Developers Share Posted October 12, 2020 (edited) Sure... But how did you resolve the regex challenge? Edited October 12, 2020 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...
JockoDundee Posted October 12, 2020 Share Posted October 12, 2020 42 minutes ago, Jos said: Sure... And yet, on my machine at least, if you have 6 notepads open, you will have to invoke the script at least 4 separate times to kill them all. As for the RegEx challenge, the record shows my initial interest, which faded when I failed to locate the canonical challenge Code hard, but don’t hard code... 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