Jump to content

run every batch file in a directory


Recommended Posts

I'm have a loop setup that runs every 3 seconds scanning a directory for batch files. I need it to be able to run any number of batch files that it finds in the directory. If I tell it the filename it works fine but in real life these batch files will have different names. The only thing they will have in common is that they are batch files and the beginning of the file name will be the same. Is there anyway I can use a wildcard to do this? I've tried but can't seem to get it to work. Thank you for any help.

Romeo

Link to comment
Share on other sites

Try modifying the following, from the help file:

; Shows the filenames of all files in the current directory.

$search = FileFindFirstFile("*.*")

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

MsgBox(4096, "File:", $file)

WEnd

; Close the search handle

FileClose($search)

If you still have no luck, post your code so far.

“Give a man a script; you have helped him for today. Teach a man to script; and you will not have to hear him whine for help.”AutoIt4UE - Custom AutoIt toolbar and wordfile for UltraEdit/UEStudio users.AutoIt Graphical Debugger - A graphical debugger for AutoIt.SimMetrics COM Wrapper - Calculate string similarity.

Link to comment
Share on other sites

Something like...

While 1
    $search = FileFindFirstFile("*.*") 

    If $search = -1 Then
    Sleep (3000)
    EndIf

        While 1
        $file = FileFindNextFile($search) 
        If @error Then ExitLoop
        If StringRight ($file,3) = "bat" then run($file)
        WEnd

; Close the search handle
FileClose($search)
Sleep (3000)

Wend
Link to comment
Share on other sites

Thanks alot guys. This worked charms. I was busy working on it and was so close. I was missing the if @error then exitloop line.

Thanks again.

Romeo

Something like...

While 1
    $search = FileFindFirstFile("*.*") 

    If $search = -1 Then
    Sleep (3000)
    EndIf

        While 1
        $file = FileFindNextFile($search) 
        If @error Then ExitLoop
        If StringRight ($file,3) = "bat" then run($file)
        WEnd

; Close the search handle
FileClose($search)
Sleep (3000)

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