-4

SSIS のスクリプト タスクを使用して、特定のフォルダー内のファイルを列挙する方法を教えてください。

4

1 に答える 1

1

ファイルのリストを受け取るために、読み取り専用文字列User::download_pathと読み取り/書き込みオブジェクトの 2 つの変数を構成します。User::files_to_process

public void Main()
{
    bool fireAgain = true;

    var filesToProcess = new System.Collections.ArrayList();
    var filesInDirectory = new System.Collections.ArrayList();

    var download_path = (String)Dts.Variables["User::download_path"].Value;

    // Find for example all csv files in the directory which are having size > 0 
    var downloadedFiles = new DirectoryInfo(download_path).EnumerateFiles("*.csv",SearchOption.TopDirectoryOnly);
    foreach (var f in downloadedFiles)
    {
        if (f.Length > 0)
            filesInDirectory.Add(f.FullName);
    }

    Dts.Events.FireInformation(3, "Getting files in directory", downloadedFiles.Count().ToString() + " found.", "", 0, ref fireAgain);

    // Report the file names into the SSIS Log:
    foreach (var f in filesToProcess)
    {
        Dts.Events.FireInformation(3, f.ToString(), "Ready for processing", "", 0, ref fireAgain);
    }

    // Return them into the READWRITE object variable
    Dts.Variables["User::files_to_process"].Value = filesInDirectory;

    Dts.TaskResult = (int)ScriptResults.Success;
}
于 2012-11-02T08:06:36.133 に答える