File system task question
Hello-
I’m having an issue with a For each loop with file system task and I’m pretty sure it’s something small that I’m over looking. My SSIS experience is minimal at best but here it goes.
What I’m attempting to do is copy a file from one destination to another. The file names all have current date in the file name. I have an expression in my variable that copies today’s file using GETDATE() so no issue there. If the file exists in
the source directory everything completes successfully.
Problem I’m having, is if the file does not exists in the source directory, it errors out.
I do not expect a current day file in the source directory every single day. If the file does not exist I would like to task to not error out, that’s pretty much it.
Any suggestions are appreciated!
December 21st, 2010 9:46am
How about checking first if the file exists before copying the file. One interesting approach you can try is described here:
http://dichotic.wordpress.com/2006/11/01/ssis-test-for-data-files-existence/Arthur My Blog
Free Windows Admin Tool Kit Click here and download it now
December 21st, 2010 10:06am
Use the following code in script task and replace the respective path
Dim var
As System.IO.File
If var.Exists("c:\testfile.txt")
Then
var.Copy(
"c:\testfile.txt",
"d:\testfile.txt")
End
If
Cheers , Varun
December 21st, 2010 10:19am
Use the following code in script task and replace the respective path
Dim var
As System.IO.File
If var.Exists("c:\testfile.txt")
Then
var.Copy(
"c:\testfile.txt",
"d:\testfile.txt")
End
If
Cheers , Varun
Thanks, but will this work with my variable expression below? This is the variable that I have set to determine the current date and grab the file that has that date in the file name?
"D:\\test\\Support\\Folder\\ARC\\Inbound\\ARC_test_report_" + (DT_STR, 4, 1252) YEAR( GETDATE() ) + (LEN((DT_STR, 2, 1252) MONTH( GETDATE() ) ) == 1 ? ("0" + (DT_STR, 2, 1252) MONTH( GETDATE() ) ) : (DT_STR,
2, 1252) MONTH( GETDATE() ) ) + (LEN((DT_STR, 2, 1252)DAY( GETDATE() ) ) == 1 ? ("0" + (DT_STR, 2, 1252) DAY( GETDATE() ) ) : (DT_STR, 2, 1252) DAY( GETDATE() ) ) + ".txt"
Free Windows Admin Tool Kit Click here and download it now
December 21st, 2010 10:43am
That script won't work because the file name is hardcoded, but you can refer to the variable you've made that does hold the file name. There are some script samples here that might help:
Script Task - File Properties. Or you can use an all-in-one custom task:
File Properties Task.
Talk to me now on
December 22nd, 2010 2:32am