diff --git a/ImportService/TrackingDataImport.vbs b/ImportService/TrackingDataImport.vbs new file mode 100644 index 0000000..d02bf03 --- /dev/null +++ b/ImportService/TrackingDataImport.vbs @@ -0,0 +1,69 @@ +Option Explicit +Dim dev:dev = True +Dim DataDirectory +Dim glob:set glob = CreateObject("Chilkat_9_5_0.Global") +Dim success:success = glob.UnlockBundle("KENTCM.CB1022025_RGzBPM5J655e") + + If (success <> 1) Then + WriteLine(glob.LastErrorText) + WScript.Quit + End If + +Dim objCSV:Set objCsv = CreateObject("Chilkat_9_5_0.Csv") +Dim WorkingDirectory:WorkingDirectory = Replace(WScript.ScriptFullName,WScript.ScriptName,"") + If dev Then + DataDirectory = WorkingDirectory & "test" + Else + DataDirectory = "\\kci-syn-cl01\PC Transfer\TrackingDataImport\" + End If +CheckForFiles + +Function CheckForFiles() +Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject") + + If objFSO.FolderExists(DataDirectory) Then + Dim objFolder:Set objFolder = objFSO.GetFolder(DataDirectory) + + If objFolder.Files.Count > 0 Then + WScript.Echo "Files found in directory: " & DataDirectory + Dim objFile + For Each objFile In objFolder.Files + Dim CsvString:CsvString = ConvertCsvToString(objFile.Path) + If ValidImportCSV(CsvString) Then + WScript.Echo objFile.Path & " Is a Valid CSV for Importing" + End If + Next + Else + WScript.Echo "No files found in directory: " & DataDirectory + End If + + End If +End Function + +Function ConvertCsvToString(FilePath) + Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject") + Dim objCsvFile:set objCsvFile = objFSO.OpenTextFile(FilePath) + Dim strContent:strContent = "" + Dim intLineCount:intLineCount = 0 + Do Until objCsvFile.AtEndOfStream Or intLineCount >= 3 + objCsvFile.SkipLine + intLineCount = intLineCount + 1 + Loop + ' Read the remaining content into a string + + Do Until objCsvFile.AtEndOfStream + Dim strLine:strLine = objCsvFile.ReadLine + strContent = strContent & strLine & vbCrLf + Loop + +ConvertCsvToString = strContent +End Function + +Function ValidImportCSV(CsvFileAsString) + objCSV.LoadFromString(CsvFileAsString) + If objCSV.NumColumns = 20 Then + ValidImportCSV = True + Else + ValidImportCSV = False + End If +End Function \ No newline at end of file