Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2014-06-04 : 03:00:05
|
I want to check if the file exists or not at a particular location, using c# script task in ssis 2008R2
below is the code I am using in script task, however every time I am getting false output, but there are 3 files at that location
vStrFilePath: has path for file in default vBolFileExist: is a Boolean variable declared with default value as false
public void Main() { if (File.Exists(Dts.Variables["User::vStrFilePath"].Value.ToString())) { Dts.Variables["User::vBolFileExist"].Value = true; MessageBox.Show(Dts.Variables["User::vBolFileExist"].Value.ToString()); } else { Dts.Variables["User::vBolFileExist"].Value = false; MessageBox.Show(Dts.Variables["User::vBolFileExist"].Value.ToString()); } Dts.TaskResult = (int)ScriptResults.Success; }
-Neil |
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2014-06-04 : 06:09:02
|
any updates? or you need more inputs
-Neil |
 |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-06-04 : 08:16:59
|
It would be helpful to see the actual values passed in the variable vStrFilePath and a (at least partial) directory listing from that exact path. |
 |
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2014-06-04 : 09:15:51
|
In "vStrFilePath" I am passing C:\Users\Neil\Desktop\CTData and in "vBolFileExist" default is False.. it is not taking the default value it is going to the else part if the if, I verified this
-Neil |
 |
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2014-06-04 : 09:35:39
|
oh.. when I added the file name to the path it is working C:\Users\Neil\Desktop\CTData\file.accdb
How can I pass this dynamically at least can I check *.accdb ?
-Neil |
 |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-06-04 : 14:39:13
|
quote: Originally posted by aakcse
oh.. when I added the file name to the path it is working C:\Users\Neil\Desktop\CTData\file.accdb
How can I pass this dynamically at least can I check *.accdb ?
-Neil
File.Exists() looks for a specific file. You probably want Directory.EnumerateFiles() instead |
 |
|
aakcse
Aged Yak Warrior
570 Posts |
Posted - 2014-06-04 : 15:22:17
|
Directory.EnumerateFiles()
... hmm there are other files as well there I just want system to look for .accdb file and pick one by one and load it into one target table
-Neil |
 |
|
gbritton
Master Smack Fu Yak Hacker
2780 Posts |
Posted - 2014-06-05 : 10:53:32
|
Did you look up the method? It has three signatures. The second is the one you want, e.g.
Directory.EnumerateFiles("C:\\temp\\", "*.txt")
|
 |
|
jeffw8713
Aged Yak Warrior
819 Posts |
Posted - 2014-06-05 : 14:06:08
|
You don't need a script task to do that - you can use the built-in tasks to get a list of files from a directory. |
 |
|
|
|
|