2014-09-24 1 views
0

에 파일을 이동 나는이 있습니다다른 폴더

파일이 어떤 값처럼
File.Move(file, trashFolderPath + "\\" + file); 

:

C:\mytest\Images\Hannah, Pow, 199169, 211 Addendum.pdf 

와 두 번째 매개 변수가 모두 함께 같은 값이 있습니다

"C:\\mytest\\ImagesNotFound\\C:\\mytest\\Images\\Hannah, Pow, 199169, 211 Addendum.pdf" 

을 하지만이 예외가 발생합니다.

The given path's format is not supported. 
+2

두 번째 매개 변수에 C : \\가 두 번 있기 때문입니다. "C : \\ mytest \\ Images \\ Hannah ...."이어야합니다. –

+0

이 ** C : \\ mytest \\ ImagesNotFound \\ C : \\ **가 유효한 경로? – Neolisk

+0

디렉토리 확장없이 파일 이름을 얻으려면'File' 클래스를 사용해야합니다. –

답변

4

전체 경로가 포함되어 있으며 경로가 Target 인 경우 전체 파일 이름을 사용하고 있습니다. 디렉토리 문자 C:을 확인하십시오. 사용 :

File.Move(file, Path.Combine(trashFolderPath,Path.GetFileName(file))); 
2

"C : \ MYTEST \ ImagesNotFound \ C : \ MYTEST \ 이미지 \ 한나, 탕 또한 같은 합치 경로의 Path.Combine를 대신 사용할 수 있습니다

Path.GetFileName

File.Move(file, trashFolderPath + "\\" + Path.GetFileName(file)); 

, 199169, 211 Addendum.pdf "는 유효한 파일 경로가 아닙니다. 따라서 get the file namefile에서 가져온 다음 trashFolderPath에 추가하십시오.

File.Move(file, Path.Combine(trashFolderPath, Path.GetFileName(file)); 

사용 Path.Combine()

경로 이름을 결합합니다. 자동으로 적절한 디렉토리 분리 기호를 사용하므로 코드가 더 이식성이 있습니다.