November 7, 2016 at 2:31 pm
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?
November 8, 2016 at 8:50 am
The files are processed in alphabetical order. If you follow the naming convention of having a fixed filename prefix with a timestamp suffix in YYYYMMDDHHMMSS order they will be processed in datetime order.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
November 8, 2016 at 2:04 pm
drew.allen (11/8/2016)
The files are processed in alphabetical order. If you follow the naming convention of having a fixed filename prefix with a timestamp suffix in YYYYMMDDHHMMSS order they will be processed in datetime order.Drew
Yowch! Did not know that you couldn't interrogate file dates in SSIS.
--Jeff Moden
Change is inevitable... Change for the better is not.
November 9, 2016 at 2:28 pm
Hi Guys,
I solved this using Script task.
I added a foreach loop container and a script task and added below code
var directory = new DirectoryInfo(Dts.Variables["User::remoteFolder"].Value.ToString());
FileInfo[] files = directory.GetFiles();
DateTime lastModified = DateTime.MaxValue;
foreach (FileInfo file in files)
{
if (file.LastWriteTime < lastModified)
{
lastModified = file.LastWriteTime;
Dts.Variables["User::VarFileName"].Value = file.ToString();
}
}
Dts.TaskResult = (int)ScriptResults.Success;
}
}
Then I added my regular foreach loop container inside this foreach loop container by reading the file got by this script task.
Now I can pick the first file first.
Thanks for all your help
November 9, 2016 at 10:31 pm
Jeff Moden (11/8/2016)
drew.allen (11/8/2016)
The files are processed in alphabetical order. If you follow the naming convention of having a fixed filename prefix with a timestamp suffix in YYYYMMDDHHMMSS order they will be processed in datetime order.Drew
Yowch! Did not know that you couldn't interrogate file dates in SSIS.
One can and it's easy using something like the FileInfo Class
😎
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply