I am not good at c#. I got script task that deletes the existing file from directory, I got variable that holds both directory value and file value. how can I use those variable values in this code?:
public void Main()
{
// TODO: Add your code here
string directoryPath = @"\\sql\sqlfiles;
string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "MYDBFULL_*.bak");
foreach (string currFile in oldFiles)
{
FileInfo currFileInfo = new FileInfo(currFile);
currFileInfo.Delete();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
I want to use variable value here at @"\\\\sql\\sqlfiles
and MYDBFULL_*.bak
Thnak you in advance
Found Ans. For anybody for future ref:
Since my variables are dynamic, means every time it changes its values. In script task take those as read and write variables. and add this code.
public void Main()
{
// TODO: Add your code here
string directoryPath = Dts.Variables["User::DestinationFilePath"].Value.ToString();
string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, Dts.Variables["User::VarFileName"].Value.ToString());
foreach (string currFile in oldFiles)
{
FileInfo currFileInfo = new FileInfo(currFile);
currFileInfo.Delete();
}
Dts.TaskResult = (int)ScriptResults.Success;
}
hope this helps.
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.