// FileCompleteDelete.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" using namespace System; using namespace System::IO; int main(array ^args) { String^ path = "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\CompleteDeleteFile\\CompleteDeleteFileFrom\\CompleteDeleteFileFrom.txt"; String^ path2 = "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\CompleteDeleteFile\\CompleteDeleteFileTo\\CompleteDeleteFileTo.txt"; FileInfo^ fi1 = gcnew FileInfo(path); try { StreamWriter^ sw = fi1->CreateText(); if (sw) delete (IDisposable^)sw; FileInfo^ fi2 = gcnew FileInfo(path2); //Ensure that the target does not exist. fi2->Delete(); //Copy the file. fi1->CopyTo(path2); Console::WriteLine("{0} was copied to {1}.", path, path2); //Delete the newly created file. fi2->Delete(); Console::WriteLine("{0} was successfully deleted.", path2); } catch (Exception^ e) { Console::WriteLine( "The process failed: {0}", e ); } return 0; }