简体   繁体   中英

SSIS Script Task check if file exists

I'm trying to use a script task to check if a file is in a folder. If the file is there then the package will continue through its steps, if not it should quit. I have a variable User::uvIfExistsFileName which is used by a C# script to check and see if the file exists in a certain location. Right now, I have to use the full file name, ie data.csv and the precedence constraint will only return true if the file name matches. What I would like to do is change the value of the IfExistsFileName variable which is a string from data.csv to *.csv. But when I chance the first part of the variable to a wild card it returns unmatched. Which I'm sure its supposed to, I just don't know how to get it to return true when any .csv file is present. My for each loop which comes after in the process uses wildcards just fine but my script is not having any of it.

Thanks for your help in advance.

You need to add another variable that holds path w/o file name and use Directory.GetFiles probably like this:

string[] files = System.IO.Directory.GetFiles(Dts.Variables["User::FolderPath"].Value.ToString(), 
"*.csv", System.IO.SearchOption.TopDirectoryOnly);
if (files.Length > 0)
    Dts.Variables["User::CsvFileExists"].Value = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM