Jump to content

How to include multiple filters


ur
 Share

Recommended Posts

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

  • Developers
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

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 by ur
Link to comment
Share on other sites

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

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

  • Developers

.. 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

  • Developers

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

  • Developers

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

  • Developers

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

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

  • Developers
Just now, ur said:

Hi, yes with process ID it is terminating.

Which makes a lot of sense ...right?

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

  • Developers

Sure... But how did you resolve the regex challenge? ;)

Edited 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...