Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server SSI正在foreach循环中检索当前文件夹,该循环遍历子文件夹_Sql Server_Loops_Ssis - Fatal编程技术网

Sql server SSI正在foreach循环中检索当前文件夹,该循环遍历子文件夹

Sql server SSI正在foreach循环中检索当前文件夹,该循环遍历子文件夹,sql-server,loops,ssis,Sql Server,Loops,Ssis,我使用SSI读取输入中的.txt文件,并在其上执行业务逻辑,将输出结果保存在一个文件中,该文件的名称与当前输入输出文件(文件名动态存储在变量中)相同 当所有文件都存储在同一个文件夹中时,我访问它们没有问题,因为我在数据流中使用以下表达式作为平面文件连接字符串:“path”+@[User::inputFileName]+.txt” 现在我必须处理一个包含子文件夹的文件夹(我在foreach循环中设置了transverse subfolders),平面文件连接字符串有一些问题,因为我不能使用通配符,

我使用SSI读取输入中的.txt文件,并在其上执行业务逻辑,将输出结果保存在一个文件中,该文件的名称与当前输入输出文件(文件名动态存储在变量中)相同

当所有文件都存储在同一个文件夹中时,我访问它们没有问题,因为我在数据流中使用以下表达式作为平面文件连接字符串:
“path”+@[User::inputFileName]+.txt”

现在我必须处理一个包含子文件夹的文件夹(我在foreach循环中设置了transverse subfolders),平面文件连接字符串有一些问题,因为我不能使用通配符,例如:
my path\\subfolder*“+@[User::inputFileName]+.txt”
,其中每个子文件夹都有相同的名称,并且只更改名称的最后一部分


如何将当前子文件夹名称保存在变量中,以便按以下方式使用它?
“path\\\”++[User::currentSubFolder]+“\\”++[User::inputFileName]+.txt”

我能够解决我的问题,因此我在这里写下我的解决方案,以防其他人遇到同样的情况

我在foreach循环之前使用了一个脚本转换块。我可以从中检索当前完整路径(之后在平面文件连接字符串中使用)和输入文件名(不带扩展名),以用作包含SSIS脚本结果的输出文件名

为了保持兴趣值,我使用了两个变量:一个用于文件名,另一个用于路径

下面是脚本代码:

Public Sub Main()

    'Variable Index 0 => FileName
    'Variable Index 1 => filePath

    Dim fullPath As String = Dts.Variables.Item(1).Value.ToString
    Dim fileName As String = Path.GetFileName(fullPath)
    fileName = fileName.Substring(0, fileName.Length - 4) 

    Dts.Variables.Item(0).Value = fileName
    Dim x As String = Dts.Variables.Item(0).Value.ToString

    Dts.TaskResult = Dts.Results.Success
End Sub

我能够解决我的问题,因此我在这里写下我的解决方案,以防其他人也遇到同样的情况

我在foreach循环之前使用了一个脚本转换块。我可以从中检索当前完整路径(之后在平面文件连接字符串中使用)和输入文件名(不带扩展名),以用作包含SSIS脚本结果的输出文件名

为了保持兴趣值,我使用了两个变量:一个用于文件名,另一个用于路径

下面是脚本代码:

Public Sub Main()

    'Variable Index 0 => FileName
    'Variable Index 1 => filePath

    Dim fullPath As String = Dts.Variables.Item(1).Value.ToString
    Dim fileName As String = Path.GetFileName(fullPath)
    fileName = fileName.Substring(0, fileName.Length - 4) 

    Dts.Variables.Item(0).Value = fileName
    Dim x As String = Dts.Variables.Item(0).Value.ToString

    Dts.TaskResult = Dts.Results.Success
End Sub