SQLSearcher
asked on
SSIS Script Task pick up the latest CSV file
Hello Experts Exchange
I have found a web page that tells me how to pick up the latest file from a folder using SSIS Scripted Task.
Here is the web page;
http://www.techbrothersit.com/2013/12/ssis-how-to-get-most-recent-file-from.html
It has a bit of code that gets the latest file name.
How do I change the code so it only looks for *.CSV files as my folder has a mixture of file types?
Regards
SQLSearcher
I have found a web page that tells me how to pick up the latest file from a folder using SSIS Scripted Task.
Here is the web page;
http://www.techbrothersit.com/2013/12/ssis-how-to-get-most-recent-file-from.html
It has a bit of code that gets the latest file name.
var directory= new DirectoryInfo(Dts.Variables["User::VarFolderPath"].Value.ToString());
FileInfo[] files = directory.GetFiles();
DateTime lastModified = DateTime.MinValue;
foreach (FileInfo file in files)
{
if (file.LastWriteTime > lastModified)
{
lastModified = file.LastWriteTime;
Dts.Variables["User::VarFileName"].Value = file.ToString();
}
}
How do I change the code so it only looks for *.CSV files as my folder has a mixture of file types?
Regards
SQLSearcher
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Don't use this line:
Only use the other one.
What version of .NET are you using?
"I need this line to work as I'm not sure that csv will never be in the file name."
Can you rephrase this comment?
FileInfo[] files = directory.GetFiles().Where(s => s.EndsWith(".csv") );
Only use the other one.
What version of .NET are you using?
"I need this line to work as I'm not sure that csv will never be in the file name."
Can you rephrase this comment?
ASKER
Thank you very much.
I did a test with a file name that had csv in the name not the extension and it worked correctly and was not pick up by the code.
The code that worked was;
FileInfo[] files = directory.GetFiles("*.csv" );
Regards
SQLSearcher
I did a test with a file name that had csv in the name not the extension and it worked correctly and was not pick up by the code.
The code that worked was;
FileInfo[] files = directory.GetFiles("*.csv"
Regards
SQLSearcher
ASKER
This line of code you have given me works.
Open in new window
but the other line you have given me does not work.
Open in new window
It has a problem with the Where and underlines it in red.
I need this line to work as I'm not sure that csv will never be in the file name.
Regards
SQLSearcher