Djamille Djamille - 1 year ago 71
Ini Question

How to put a 2 array variables in config (.ini) file?

I have this VBScript that send specific files to FTP based on the file name.

Option Explicit
Dim objFSO, objMyFile, objShell, strFTPScriptFileName, strFilePut
Dim strLocalFolderName, strScriptFolder, strFTPServerName, strLoginID, strReportPath
Dim strPassword, strFTPServerFolder

Dim objArg, strIniFilePath, oShell

Dim i: i = 0

'Locates the INI File
Set objArg = WScript.Arguments
strIniFilePath = objArg(0)

'Gets FTP UserId and Password
strLocalFolderName = ReadIni(strIniFilePath,"FTP","LocalFolderName")
strFTPServerName = ReadIni(strIniFilePath,"FTP","FTPServerName")
strLoginID = ReadIni(strIniFilePath,"FTP","LoginID")
strPassword = ReadIni(strIniFilePath,"FTP","Password")

strFTPScriptFileName = ReadIni(strIniFilePath,"FTP","FTPScriptFileName")

strReportPath= Array("/davaoccc" , "/calambaccc" , "/cebuccc")
strFilePut= Array("0970*.txt" , "0979*.txt" , "0983*.txt")

Set oShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFSO = CreateObject("Scripting.FileSystemObject")

If (objFSO.FileExists(strFTPScriptFileName)) Then
objFSO.DeleteFile (strFTPScriptFileName)
End If

For i = 0 To UBound(strReportPath)
Set objMyFile = objFSO.CreateTextFile(strFTPScriptFileName, True)
objMyFile.WriteLine ("open " & strFTPServerName)
objMyFile.WriteLine (strLoginID)
objMyFile.WriteLine (strPassword)
objMyFile.WriteLine ("cd " & strReportPath(i))
objMyFile.WriteLine ("bin")
objMyFile.WriteLine ("lcd " & strLocalFolderName)
objMyFile.WriteLine ("prompt off")
objMyFile.WriteLine ("mput " & strFilePut(i))
objMyFile.WriteLine ("disconnect")
objMyFile.WriteLine ("bye")

'Execute the FTP script.
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run "ftp -s:" & Chr(34) & strFTPScriptFileName & Chr(34), , True


This is the .ini file


As you can see, the values of the variables is in the .ini file (hardcoded value should be in the .ini files) but except for the two variables: strReportPath, strFilePut

There are multiple destination folder in the FTP, and different files based on the filename (files starts with 0970, 0979, 0983) in which, this VBScripts successfully sends. But I am having a hard time on how to put a 2 array variables in config ini file in a way that the array variable is still in match. (e.g. /davaoccc for 0970, /calambaccc for 0979, /cebuccc for 0983)

Anyone know or have an idea to do it?

I tried to search for this on the internet but no topic for this one. A big appreciation for the answer.

Answer Source

Put array elements in a comma separated list, then write some VBscript to parse these values.

strReportPath = /davaoccc,/calambaccc,/cebuccc

strFilePut= 0970*.txt,0979*.txt,0983*.txt

I assume all values are read as text, so you can drop the string quotes.