// FileCopy.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" using namespace System; using namespace System::IO; int main(array ^args) { String^ path = "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\CopyFile\\CopyFileFrom\\FileCopy.cpp"; String^ path2 = "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\CopyFile\\CopyFileTo\\FileCopy.cpp"; try { // Create the file and clean up handles. IDisposable^ file = (IDisposable^)(File::Create(path)); if (file) delete file; // Ensure that the target does not exist. File::Delete(path2); // Copy the file. File::Copy(path, path2); Console::WriteLine( "{0} copied to {1}", path, path2 ); // Try to copy the same file again, which should succeed. File::Copy(path, path2, true); Console::WriteLine("The second Copy operation succeeded, which was expected."); } catch (Exception^) { Console::WriteLine("Double copy is not allowed, which was not expected."); } return 0; }