파일을 복사하고 이름을 바꾸고 새 위치로 옮깁니다. 디렉토리 TestFiles2에더 나은 방법 복사 이동 이름 바꾸기 파일, Visual Basic (VS 2012 V11)
이 예제 파일을 복사 TEST.TXT을하고 는 NEWFILE.TXT 이름을 바꿉니다 : http://msdn.microsoft.com/en-us/library/36xbexyf(v=vs.90).aspx에 따르면, 다음 코드는 그렇게해야한다.
My.Computer.FileSystem.CopyFile _
("C:\UserFiles\TestFiles\test.txt", _
"C:\UserFiles\TestFiles2", "NewFile.txt", FileIO.UICancelOption.DoNothing)
그러나, 나는 단지 덮어 쓰기를 처리하는 부울 매개 변수로 "NEWFILE.TXT"매개 변수를보고이 코드를 입력 할 때. 나는 이것이 웹 사이트 부분의 실수라고 생각한다.
' Rename the file to be copied the name you want it to be in the new location
My.Computer.FileSystem.RenameFile("C:\OriginalFile.txt", "OriginalFileTemporaryName.txt")
' Copy the file to the new location and overwrite if it exists there
My.Computer.FileSystem.CopyFile ("C:\OriginalFileTemporaryName.txt", "C:\UserFiles\TestFiles2", True)
' Rename the original file back to it's original name
My.Computer.FileSystem.RenameFile("C:\OriginalFileTemporaryName.txt", "OriginalFile.txt")
: 이름을 변경하고 파일을 이동 복사 (내가 뭔가 잘못하고있는 중이 아닌 경우) 내가 "My.Computer.FileSystem.CopyFile"를 사용할 수없는 경우
, 더 좋은 방법은 다음이가 위의 문제는 원본 파일의 이름을 원래 파일 위치에 이미 존재하는 임시 이름으로 바꿀 수 있다는 것입니다. 나는 그것을 피하고 싶다. 또한 "My.Computer.FileSystem.RenameFile"에 대해 덮어 쓰기 옵션을 표시하지 않기 때문에 대상 폴더에서 복사 한 파일의 이름을 바꾸고 싶지 않습니다.
이 방법도 절반으로 괜찮습니까? 더 좋은 방법이 없습니까?