// FileGetCreationTime.cpp : メイン プロジェクト ファイルです。 #include "stdafx.h" using namespace System; using namespace System::IO; int main(array<System::String ^> ^args) { try { String^ path = "C:\\MyFolder\\Homepage\\public_html\\Cprpr\\GetCreationTimeFile\\GetCreationTimeFile.txt"; if ( !File::Exists( path ) ) { File::Create( path ); } File::SetLastAccessTime( path, DateTime(2009, 12, 14) ); // Get the creation time of a well-known directory. DateTime dt = Directory::GetCreationTime( Environment::CurrentDirectory ); // Give feedback to the user. if ( DateTime::Now.Subtract( dt ).TotalDays > 364 ) { Console::WriteLine( "This directory is over a year old." ); } else if ( DateTime::Now.Subtract( dt ).TotalDays > 30 ) { Console::WriteLine( "This directory is over a month old." ); } else if ( DateTime::Now.Subtract( dt ).TotalDays <= 1 ) { Console::WriteLine( "This directory is less than a day old." ); } else { Console::WriteLine( "This directory was created on {0}.", dt ); } // Get the creation time of a well-known directory. dt = File::GetLastWriteTime( path ); Console::WriteLine( "The last write time for this file was {0}.", dt ); // Get the creation time of a well-known directory. dt = File::GetLastAccessTime( path ); Console::WriteLine( "The last access time for this file was {0}.", dt ); // Update the last access time. File::SetLastAccessTime( path, DateTime::Now ); dt = File::GetLastAccessTime( path ); Console::WriteLine( "The last access time for this file was {0}.", dt ); } catch ( Exception^ e ) { Console::WriteLine( "The process failed: {0}", e ); } return 0; }