如何在 SSIS 的 For Each 循环容器中查找文件的大小?
How to find the size of a file in a For Each Loop Container in SSIS?
我正在尝试查找我的 FELC 中文件的大小。我使用了以下代码,但一直出现错误。这是我的脚本任务中的代码。
Public Sub Main()
Dim LoopFilePath As String = Dts.Variables("User::vvarcharsource").Value.ToString
Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo(LoopFilePath)
Dts.Variables("User::vintsize").Value = infoReader.Length
Dts.TaskResult = ScriptResults.Success
End Sub
我使用了一个 varchar 类型的读取变量 vvarcharsource 和一个 double 类型的读写变量 vintsize。
我得到的错误是:
Exception has been thrown by the target of an invocation.
我不完全明白你在这里想做什么。
"DTS variable" 这是什么?
我也不知道你对 FELC 的意思
(google 说第一英国路德教会或其他东西,所以解释会很好;))
也许你把它拆分成更多的单一函数来查看它到底在哪里失败了,现在很难知道发生了什么
我会把文件大小部分放到这样的地方(你甚至可能想构建一个 returns 你想要的值的函数)
Public Sub GetFileInfo(ByVal Path As String)
If System.IO.File.Exists(Path) Then
Dim Fi As New FileInfo(Path)
Dim FileSize As Long
Dim FilsizeInt As Integer
FileSize = Fi.Length
FilsizeInt = CInt(Math.Round(FileSize / 1024))
MsgBox("filesize is about " & FilsizeInt & " kb")
Else
MsgBox("file not found")
End If
End Sub
hth
将 User::vintsize 的数据类型转换为 varchar 解决了问题
我正在尝试查找我的 FELC 中文件的大小。我使用了以下代码,但一直出现错误。这是我的脚本任务中的代码。
Public Sub Main()
Dim LoopFilePath As String = Dts.Variables("User::vvarcharsource").Value.ToString
Dim infoReader As System.IO.FileInfo
infoReader = My.Computer.FileSystem.GetFileInfo(LoopFilePath)
Dts.Variables("User::vintsize").Value = infoReader.Length
Dts.TaskResult = ScriptResults.Success
End Sub
我使用了一个 varchar 类型的读取变量 vvarcharsource 和一个 double 类型的读写变量 vintsize。
我得到的错误是:
Exception has been thrown by the target of an invocation.
我不完全明白你在这里想做什么。 "DTS variable" 这是什么? 我也不知道你对 FELC 的意思 (google 说第一英国路德教会或其他东西,所以解释会很好;))
也许你把它拆分成更多的单一函数来查看它到底在哪里失败了,现在很难知道发生了什么
我会把文件大小部分放到这样的地方(你甚至可能想构建一个 returns 你想要的值的函数)
Public Sub GetFileInfo(ByVal Path As String)
If System.IO.File.Exists(Path) Then
Dim Fi As New FileInfo(Path)
Dim FileSize As Long
Dim FilsizeInt As Integer
FileSize = Fi.Length
FilsizeInt = CInt(Math.Round(FileSize / 1024))
MsgBox("filesize is about " & FilsizeInt & " kb")
Else
MsgBox("file not found")
End If
End Sub
hth
将 User::vintsize 的数据类型转换为 varchar 解决了问题