2012-10-18 2 views
0

폴더 (C : \ Incoming)에있는 파일을 찾고 지정된 전자 메일 주소로 전자 메일을 보내는 웹 서비스가 있습니다. 그 폴더를 다른 폴더 (C : \ Processed)에 메일로 보내면 그 폴더를 이동할 수 있기를 원합니다.웹 서비스에서 한 위치에서 다른 위치로 폴더 이동

아래의 코드를 사용해 보았지만 작동하지 않습니다.

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

소스 파일을 찾을 수 없다는 오류가 발생합니다. 나는 그것이 존재하고 그것에 접근 할 수 있음을 확인했다.

+0

끝에 파일 확장명을 추가하십시오. – Zaki

답변

2

파일이 아닌 폴더를 이동하면 하나씩 복사 할 파일을 반복해야합니다.

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); 
} 
0

사용 String.Format 하나, 두 번째 사용 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); 
} 
관련 문제