C는 # 파일 달성은 다음과 같이 이름이 바뀐 세 가지 문자열 유형이 매개 변수는 통과 필요 소스 파일, 오브젝트 파일 디렉토리와 파일 이름 이름 바꾸기의 파일 디렉토리 , 코드는 다음과 같습니다 :
공개 ExecutionResult FileRename ( 문자열 은 SourceFile, 문자열 의 DestinationPath, 문자열 같이 DestinationFileName) { ExecutionResult 결과; 에서는 FileInfo tempFileInfo; 에서는 FileInfo tempBakFileInfo; 의 DirectoryInfo tempDirectoryInfo; 결과 = 새로운 ExecutionResult을 (); tempFileInfo = 새로운 에서는 FileInfo (은 SourceFile); tempDirectoryInfo = 새 의 DirectoryInfo (의 DestinationPath); tempBakFileInfo는 = 새로운에서는 FileInfo (의 DestinationPath + " \\ " + 같이 DestinationFileName); 시도 { 경우 (!의 tempDirectoryInfo.Exists) tempDirectoryInfo.Create (); 경우 (tempBakFileInfo.Exists) tempBakFileInfo.Delete (); // 이동 파일이 박하기 (의 DestinationPath + tempFileInfo.MoveTo을 " \\ " + 같이 DestinationFileName); result.Status는 = 진정한 ; result.Message = " 이름 바꾸기 파일 확인 " ; result.Anything = " OK를 " ; } 캐치 (예외 예) { result.Status이 = 거짓 ; result.Anything = " 메일 " ; result.Message = ex.Message; 경우 (mesLog.IsErrorEnabled) { mesLog.Error (. MethodBase.GetCurrentMethod () 이름, " . 이름 바꾸기 파일 오류 메시지 : " + ex.Message); mesLog.Error (ex.StackTrace); } } 리턴 결과; }