Trying to make a batch or VBS script that searches for files and runs them

Viewed 38

I am Trying to make a script (vbs or Batch) that searches for files in currentFolder/subdirectories based on file extension and runs them. Ive tried all afternoon but cant find a good way that works for me

the closes thing i found is this VBScript but it only finds files on same folder not subfolders and makes a list ( i dont need a list, i need it to find files in subdirectories and then run them)

But I could use either a vbs or batch

Thanks in advance!

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

EDIT "" WORKING CODE ""

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim shell, fsObj, fldr, subfldrs, sfldr, fls, sfls, ls, fl, tf


Set fsObj = CreateObject("Scripting.FileSystemObject")
Set fldr = fsObj.GetFolder(".")

'get files 
Set fls = fldr.Files

'get subfolders 
Set subfldrs = fldr.SubFolders

ls = ""

For Each sfldr in subfldrs
    
    'get subfolder files
    Set sfls = sfldr.Files

    For Each fl in sfls 
             Dim strFileName : strFileName = fl.Name
         Dim strExtension : strExtension = LCase(fsObj.GetExtensionName(strFileName))
        
        If strExtension = "vbs" Then
            ls = ls & fl.name & chr(13) & Chr(10)
                
                Set shell = CreateObject("WScript.Shell")
                shell.CurrentDirectory = sfldr

                    'TESTING
                    'Wscript.Echo shell.CurrentDirectory

                    shell.Run Chr(34) & fl & Chr(34), 1, false
                    wscript.sleep 1200
                Set shell = Nothing
        End If
    
    Next
Next

Set tf = fsObj.OpenTextFile("dirlist.txt", 2, True, True)
tf.WriteLine ls


tf.Close
Set fsObj = Nothing
0 Answers
Related