0

フォルダ(C:\ Incoming)内のファイルを検索し、指定された電子メールアドレスに電子メールで送信するWebサービスがあります。別のフォルダ(C:\ Processed)にメールが送信されたら、そのフォルダを移動できるようにしたいと思います。

以下のコードを使用してみましたが、機能しません。

 string SourceFile = "C:\\Incoming\\" + "" + Year + "" + Month + "" + Day + "";
 string destinationFile = "C:\\Processed" + "" + Year + "" + Month + "" + Day + ""; 
 System.IO.File.Move(SourceFile , destinationFile);

ソースファイルが見つからなかったというエラーが表示されます。私はそれが存在することを確認し、それにアクセスできます。

4

2 に答える 2

2

ファイルではなくフォルダーを移動しているため、ファイルを反復処理して 1 つずつコピーする必要があります。

string Source = "C:\\Incoming\\" + "" + Year + "" + Month + "" + Day + "";
string destination = "C:\\Processed" + "" + Year + "" + Month + "" + Day + "";
DirectoryInfo di = new DirectoryInfo(Source);
FileInfo[] fileList = di.GetFiles(".*.");
int count = 0;
foreach (FileInfo fi in fileList)
{
    System.IO.File.Move(Source+"\\"+fi.Name , destinationFile+"\\"+fi.Name);
}
于 2012-10-18T13:50:57.947 に答える
0

ファイルがそこにあることを確認するためにString.Format、1 回目、2 回目の使用に使用します。System.IO.File.Exists()

string SourceFile = String.Format("C:\\Incoming\\{0}{1}{2}",Year,Month,Day);
 string destinationFile = String.Format("C:\\Processed\\{0}{1}{2}",Year,Month,Day);

 if (System.IO.File.Exists(SourceFile) {
     System.IO.File.Move(SourceFile , destinationFile);
 }
于 2012-10-18T13:51:49.710 に答える