如何使用SSIS脚本组件迭代多个文件?

问题描述

我找到了以下question,它显示了一种实现脚本组件以解析平面文件中数据的好方法。就我而言,我有多个文件需要读取到脚本组件中并处理到我的数据库中。我尝试了以下方法

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    base.PreExecute();
    ///Todo:  The following string variable assumes a specific file name is to be used.  We need to iterate over all files in the path below.
    string fName = @"\\my\UNC\path";

    string[] localFiles;
    string folderPath;
    string FILE_ROOT = @"\\my\UNC\path";
    string FILE_FILTER = "*.txt";
    listForEnumerator = new ArrayList();
    GetFilesInFolder(FILE_ROOT);
    //Dts.Variables["FileList"].

    string[] lines = System.IO.File.ReadAllLines(fName);

    int ctr = 1;

    foreach (string line in lines)
    {
        string[] cols = line.Split('|');

        if (ctr != 1)
        {
            if (cols.Length == 66)
            {
                Row.TransactionHeader = cols[0].ToString();
                Row.TransactionSetIdentifierCode = cols[1].ToString();
                Row.TransactionSetControlNumber1 = cols[2].ToString();
                Row.BeginningSegment = cols[3].ToString();
                Row.TransactionSetPurposeCode = cols[4].ToString();
                Row.ReferenceIdentification = cols[5].ToString();
                Row.Date = DateTime.Parse(cols[6]).ToString();
                Row.Time = DateTime.Parse(cols[7]).ToString();
                Row.TimeCode = cols[8].ToString();
                Row.TransmittingPartyIdentification = cols[9].ToString();
                Row.EntityIdentificationCode = cols[10].ToString();
                Row.OrganizationName = cols[11].ToString();
                Row.Address1 = cols[12].ToString();
                Row.Address2 = cols[13].ToString();
                Row.City = cols[14].ToString();
                Row.State = cols[15].ToString();
                Row.ZipCode = cols[16].ToString();
                Row.AccumulatorSegment = cols[17].ToString();
                Row.HQCode = cols[18].ToString();
                Row.HQDescription = cols[19].ToString();
                Row.AccumulatorGroupNumber = cols[20].ToString();
                Row.AccumulatorDivision = cols[21].ToString();
                Row.MemberNumber = cols[22].ToString();
                Row.PersonCode = cols[23].ToString();
                Row.RelationshipCode = cols[24].ToString();
                Row.InsuredLastName = cols[25].ToString();
                Row.InsuredFirstName = cols[26].ToString();
                Row.InsuredMiddleInitial = cols[27].ToString();
                Row.InsuredSSN = cols[28].ToString();
                Row.PatientLastName = cols[29].ToString();
                Row.PatientFirstName = cols[30].ToString();
                Row.PatientMiddleInitial = cols[31].ToString();
                Row.PatientSSN = cols[32].ToString();
                Row.DateofBirth = cols[33].ToString();
                Row.Gender = cols[34].ToString();
                Row.StartDate = cols[35].ToString();
                Row.EndDate = cols[36].ToString();
                Row.AccumulatorType = cols[37].ToString();
                Row.FormularyType = cols[38].ToString();
                Row.FormularyTypeCode = cols[39].ToString();
                Row.UsedRXDeductibleAmount = Decimal.Parse(cols[40]);
                Row.UsedRXBenefitAmount = Decimal.Parse(cols[41]);
                Row.UsedRXMemberAmountOOP = Decimal.Parse(cols[42]);
                Row.ExternalUsedDeductibleAmount = Decimal.Parse(cols[43]);
                Row.ExternalUsedBenefitAmount = Decimal.Parse(cols[44]);
                Row.ExternalUsedMemberAmount = Decimal.Parse(cols[45]);
                Row.ExternalMedicalDeductibleMemberAmount = Decimal.Parse(cols[46]);
                Row.ExternalMedicalUsedBenefitAmount = Decimal.Parse(cols[47]);
                Row.ExternalMedicalUsedMemberAmount = Decimal.Parse(cols[48]);
                Row.CombinedRXDeductibleAmount = Decimal.Parse(cols[49]);
                Row.CombinedRXBenefitAmount = Decimal.Parse(cols[50]);
                Row.CombinedRXOOPAmount = Decimal.Parse(cols[51]);
                Row.Insurednumber = cols[52].ToString();
                Row.RegionCode1 = cols[53].ToString();
                Row.RegionCode2 = cols[54].ToString();
                Row.RegionCode3 = cols[55].ToString();
                Row.UsedTDSAmount = Decimal.Parse(cols[56]);
                Row.UsedTrOOPAmount = Decimal.Parse(cols[57]);
                Row.UsedPartDStandardDeductibleAmount = Decimal.Parse(cols[58]);
                Row.UsedRXCount = Decimal.Parse(cols[59]);
                Row.UsedDaysSupply = Decimal.Parse(cols[60]);
                Row.UsedQuantitySupply = Decimal.Parse(cols[61]);
                Row.CurrentEligibilityGroupNumber = cols[62].ToString();
                Row.CurrentEligibilityDivision = cols[63].ToString();
                Row.TrailerSegment = cols[64].ToString();
                Row.IncludedSegments = Decimal.Parse(cols[65]);
                Row.TransactionSetControlNumber2 = cols[66].ToString();
            }
        }
        ctr++;
    }
}
private void GetFilesInFolder(string folderPath)
{
    string[] localFiles;

    try
    {
        localFiles = Directory.GetFiles(folderPath,FILE_FILTER);
        
        if(Directory.GetDirectories(folderPath).Length > 0)
        {
            foreach(string childFolder in Directory.GetDirectories(folderPath))
            {
                GetFilesInFolder(childFolder);
            }
        }
    }
    catch(Exception ex)
    {
        
    }
}

我需要对上述脚本进行哪些更改,以确保所有文件均由该脚本组件处理?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)