使用变量将当前日期添加到文件的 SSIS 脚本 C# 脚本任务

SSIS Script C# Script Task to Add current date to a file using a variable

我有这个脚本可以将当前年月添加到目录中的文件中。它与目录路径完美配合,但我想更改变量的目录补丁,因为每个月它都会在不同的文件夹中。我已经有了要使用的目录的变量。但我不知道该怎么做,使用变量而不是目录

    public void Main()
    {
        // TODO: Add your code here

        // const string DIRECTORY_PATH = @"C:\Temp\Results"; //with this works perfect
        const string DIRECTORY_PATH =    @"@v_ResultsExcel"; //I want to use this variable

        const string FILE_NAME_TEMPLATE = "YYYY-MM";

        string previousYearMonthDate = DateTime.Now.AddYears(0).AddMonths(0).ToString("yyyy-MM");

        if (Directory.Exists(DIRECTORY_PATH))
            {
            string[] filePathList = Directory.GetFiles(DIRECTORY_PATH);

            foreach (string filepath in filePathList)
            {
                if (File.Exists(filepath))
                {
                    File.Move(filepath, filepath.Replace(FILE_NAME_TEMPLATE, previousYearMonthDate));
                }
            }
            }
        Dts.TaskResult = (int)ScriptResults.Success;
    }

在您的 SSIS 包中创建一个变量。在脚本任务 ReadOnlyVariables select User::varDir 中。 C# 代码调用只读变量。您可以编写此变量的表达式,以每月指向适当的目录。

const string DIRECTORY_PATH =  Dts.Variables["User::varDir"].Value.ToString();