0

I'm trying to write a vbScript that will execute all files in a given directory (will be mostly batch files).

I've tried to modify a script that deletes all files but I'm not able to get it to work.

Here is what I have:

Option Explicit 
'=========================================================================== 
'  Scheduled Task - Visual Basic ActiveX Script 
'=========================================================================== 
 
Call ExecuteDirectory("c:\users\public\documents\schedule\daily") 
 
 
 
'=========================================================================== 
'  Name    : ExecuteDirectory() 
'  Desc    : Executes Files from a Directory 
'=========================================================================== 
Function ExecuteDirectory(strPath2Folder) 
    Dim fso, f, fc, f1, strFiles, intFiles
	Dim WshShell

    Set WshShell = CreateObject("WScript.Shell")
 
    strFiles = "" 
 
    Set fso = CreateObject("Scripting.FileSystemObject") 
    If (fso.FolderExists(strPath2Folder)) Then 
        Set f = fso.GetFolder(strPath2Folder) 
        Set fc = f.Files 
 
        '-- Execute each file in Folder 
        For Each f1 in fc 
            strFiles = strFiles & f1.Name & vbCrLf 
msgbox strPath2Folder & "\" & strFiles
            WshShell.Run Chr(34) & strFiles & Chr(34), 1, true
        Next 
 
        Set f1 = Nothing 
        Set fc = Nothing 
        Set f = Nothing 
 
        
    End If 
    Set fso = Nothing 
End Function

The msgbox line displays the full path and file name that I want to execute, but the run line generates file not found error.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by sifuhall
0

Why are you putting a vbcrlf in the file name? Unless vbcrlf character happens to be part of the file name, don't include it as part of the file name.

MessageBox will not show you the vbcrlf character: it's invisible to the human eye.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.