1

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

user3583912
  • 1,302
  • 1
  • 17
  • 23

1 Answers1

0

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.

user3583912
  • 1,302
  • 1
  • 17
  • 23