0

特定のプロセスで実行したい、特定のパターンと拡張子を持つファイルを毎日受け取ります。フォルダーにファイルがあるかどうかを確認したいのですが、そうでない場合は別のタスクを実行します。これまでのところ、スクリプト タスクを使用して File.Exist を実行できることがわかりました。ただし、 * をワイルドカードとして使用しないため、何か間違っています。Devoluciones_source は「C:\Users\us1\Folder\」 FileToSearch は「return」

私のファイル: return_20200102.csv return_20200203.csv

String Filepath = Dts.Variables["$Project::Devoluciones_source"].Value.ToString() + Dts.Variables["User::FileToSearch"].Value.ToString() + "*csv";

        if (
            File.Exists(Filepath))

        {
            Dts.Variables["User::IsFound"].Value = 1;
        }
4

1 に答える 1

0

File.Exits() はワイルドカードを受け入れないと思います。リテラル ファイルパスをチェックし、C:\Users\us1\Folder\*.csv見つからないため false を返します。

代わりにできることは、フォルダー内のファイルを取得し、C:\Users\us1\Folder\それらを searchPattern を使用して再度チェックすることですDirectory.GetFiles(path, searchPattern)

このような:

string dirPath = Dts.Variables["$Project::Devoluciones_source"].Value.ToString(); 
string fileName = Dts.Variables["User::FileToSearch"].Value.ToString();

// if you want to make sure the directory exists:
if(Directory.Exists(dirPath) {
    string[] files = Directory.GetFiles(dirPath, fileName + "*.csv");

    if(files.lenght > 0) {
        // you can now iterate over each file that is found in the users directory that matches your pattern and do your logic.
    }
}

Directory.GetFiles メソッドの詳細: docs.Microsoft.comの Directory.GetFiles

Files.Exists メソッドの詳細: docs.Microsoft.com の Directory.GetFiles

于 2020-03-14T10:17:09.750 に答える