I have a remote folder from where i pick the multiple files and loop through for each loop container. But I want to pick the first file first based on time stamp from that folder. how do I do this in SSIS?
Asked
Active
Viewed 1,081 times
1
-
What is the version you are using? – Hadi Nov 07 '16 at 21:38
-
visual studio 2013 – unicorn Nov 07 '16 at 21:45
-
Does Remote Folder mean FTP or just a network path? Is First the oldest create timestamp, oldest modify timestamp, oldest access timestamp? – billinkc Nov 08 '16 at 01:32
1 Answers
0
First you hace to create 2 Variables
FolderPath (string) -- to store the folder you have to manipulate dtFiles (Object) -- to store files from this folder
Add a script task and select FolderPath as ReadOnlyVariable and dtFiles as ReadWrite Variable
In the script write the following code
Imports System.Collections.Generic Imports System.Linq Public Sub Main() Dim strFolderPath As String = Dts.Variables.Item("FolderPath").Value.ToString Dim lstFiles As New List(Of IO.FileInfo) For Each strFile As String In IO.Directory.GetFiles(strFolderPath, "*.*", IO.SearchOption.AllDirectories) Dim fi As New IO.FileInfo(strFile) lstFiles.Add(fi) Next Dts.Variables.Item("dtFiles").Value = lstFiles.OrderBy(Function(x) x.CreationTime).Select(Function(x) x.FullName).ToList End Sub
Connect your script task to The For each loop Container
Double Click on the ForEach Loop container and change the enumerator type to ADO enumerator and choose the variable dtFiles as a source (in the collection tab) and choose the enumeration mode (Rows from first table)
In the variable mapping tab (in For each loop container) map the index 0 to a new Variable i.e. FileName (You can use it to do your work)
Note: i used sorted files using CreationTime. You can even use LastAccessTime and LastWriteTime properties
Just add a value to FolderPath variable and Execute

Hadi
- 36,233
- 13
- 65
- 124