Link to home
Start Free TrialLog in
Avatar of donnie91910

asked on

"Expected end of statement" error in VBScript code.

I have written VBScript code to look for specific files in a folder and when the code finds the files the code will move the files to another folder.  I am able to find one file and move it, but when I try to find two or more files I get the "Expected end of statement" error.  I have included the code that I have written.  

Dim objFSO
Dim sSourceFolder
Dim sDestFolder
Dim sDBFile
Dim sDateTimeStamp
Set objFSO = CreateObject("Scripting.FileSystemObject")
sSourceFolder = "C:\Oceanside\"
sBackupFolder = "C:\Files_Found\"
sDBFile = "ROWP19-0578 PERMIT","ROWP19-0579 PERMIT"  'Expected end of statement error on this line when I try to search for two files
sDBFileExt = "pdf"
'If the backup folder doesn't exist, create it.
If Not objFSO.FolderExists(sBackupFolder) Then
End If
'Copy the file as long as the file can be found
If objFSO.FileExists(sSourceFolder & "\" & sDBFile & "." & sDBFileExt) Then
    objFSO.CopyFile sSourceFolder & "\" & sDBFile & "." & sDBFileExt,_
			sBackupFolder & "\" & sDBFile & "." & sDBFileExt
MsgBox sSourceFolder & " was copied to " & sBackupFolder
End if
Set objFSO = Nothing

Open in new window

Any help is greatly appreciated.
Avatar of Serge Fournier
Serge Fournier
Flag of Canada image

You have to define an array:

sDBFile_arr = array("ROWP19-0578 PERMIT","ROWP19-0579 PERMIT" )

then loop each element in array

for each sdbfile in sdbfile_arr
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of donnie91910


The array code worked. Thanks to both of you.