나는 아래의 코드가 그 덮어 쓰지 않고 대상 디렉토리에 파일을 복사하지만, 유지하는 것입니다 위해 내가 찾고 있어요 무엇기존 파일을 덮어 쓰지 않고 파일을 복사하려면 어떻게합니까?
string[] dirs = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly);
string[] files = Directory.GetFiles(dirs[0]);
foreach (string file in files)
{
string fname = file.Substring(dirs[0].Length + 1);
string dist = Path.Combine(dirs[1], fname);
File.Copy(file, dist, true);
}
존재하는 경우 파일을 덮어 쓰기와 복사 다른 디렉토리에서 텍스트 파일을 두 파일. 예를 들어 Windows에서와 같이 "test"라는 파일을 여러 번 복사하면
test
test - Copy
test - Copy (2)
test - Copy (3)
text
text- Copy
text- Copy (2)
text- Copy (3)
도움이 될 것입니다.
하지만이 예외는'file already exists' !!! – FSm
@ FSm yeah 죄송합니다. 추가 작업을 추가하는 것을 잊어 버렸습니다. –
@FSm 어떻게 작성해야할지 상상하지 못했습니다. 코드 –