Get LastWriteTime of Multiple Files in Directory
I'm a novice, working on an SSIS pa开发者_开发百科ckage and thanks to some assistance by talented folks here, such as yourselves, I've been able to get it to work, but am running into an issue. I need to pull data from 2 flat files and then insert it into a SQL table, to which I've added a derived column to input the LastWriteTime of the files from the directory. What's happening is that instead of pulling in the LastWriteTime of the files, it's inserting it of the directory. I know this because I've been copying/pasting different files into the directory and tried working with older files, but the date that is being inserted into the table is today's date, and not the older date of the files, themselves. I have the following that I'm using in a script task:
Public Sub Main()
Dim FilePath As String = "D:\InputFiles\"
Dim finf As New System.IO.FileInfo(FilePath)
Dts.Variables("User::FileDate").Value = finf.LastWriteTime
Dts.TaskResult = ScriptResults.Success
EndSub
Any advice, please?
You're getting a FileInfo
for the directory.
Instead, you need to get multiple FileInfo
s for the files in the directory, by calling new DirectoryInfo(path).GetFiles()
.
精彩评论