Hi.
I received this script awhile back and tried to transfer it to Visual Studio 2008. I made some changes because it would not run from vbscript to visual basic but I still keep getting one error message and was hoping someone could help me. The code is below:
Dim strTargetFolder, strTargetFolder2
Dim strSourceFolder
Dim strDataToFind, strDataToFind2 As Array
Dim objFile, strData
Dim Array() As String
Dim boolMatch1, boolMatch2 As Boolean
strTargetFolder = "C:\test"
strTargetFolder2 = "C:\test1"
strSourceFolder = "D:\testfiles\"
strDataToFind = Array("1^w", "2^w", "3^w", "4^w", "5^w", "6^w")
strDataToFind2 = Array("1^m", "2^m", "3^m")
Dim FSO, oFolder, oFile
FSO = CreateObject("Scripting.Fi
leSystemOb
ject")
Const intForReading = 1
oFolder = FSO.GetFolder(strSourceFol
der)
For Each oFile In oFolder.Files
objFile = FSO.OpenTextFile(oFile.Pat
h, intForReading, False)
strData = objFile.ReadAll
objFile.Close()
objFile = Nothing
If oFile.Size < 1024 Then
' Check for the existence of any element from strDataToFind
boolMatch1 = False
For Each strBit In strDataToFind
If InStr(LCase(strData), LCase(strBit)) > 0 Then
boolMatch1 = True
Exit For
End If
Next
If boolMatch1 = True Then
'Move file
FSO.MoveFile(oFile.Path, strTargetFolder)
End If
' Check for the existence of any element from strDataToFind2
If boolMatch1 = False Then
boolMatch2 = False
For Each strBit In strDataToFind2
If InStr(LCase(strData), LCase(strBit)) > 0 Then
boolMatch2 = True
Exit For
End If
Next
If boolMatch2 = True Then
'Move file
FSO.MoveFile(oFile.Path, strTargetFolder2)
End If
End If
' Now check if nothing was found, delete the file
If boolMatch1 = False And boolMatch2 = False Then
FSO.Deletefile(oFile.Path,
True)
End If
End If
Next
FSO = Nothing
End Sub
I keep receiving this message: Error2 Number of indices exceeds the number of dimensions of the indexed array.
I've tried making several changes to the Array but to no luck.
Any help would be appreciated.
Thank you.
Start Free Trial