Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following code example demonstrates the FileInfo class. When you have the name of a file, you can use this class to retrieve information about the file such as the file size, directory, full name, and date and time of creation and of the last modification.
This code retrieves file information for Notepad.exe.
Example
// file_info.cpp
// compile with: /clr
using namespace System;
using namespace System::IO;
int main()
{
array<String^>^ args = Environment::GetCommandLineArgs();
if (args->Length < 2)
{
Console::WriteLine("\nUSAGE : file_info <filename>\n\n");
return -1;
}
FileInfo^ fi = gcnew FileInfo( args[1] );
Console::WriteLine("file size: {0}", fi->Length );
Console::Write("File creation date: ");
Console::Write(fi->CreationTime.Month.ToString());
Console::Write(".{0}", fi->CreationTime.Day.ToString());
Console::WriteLine(".{0}", fi->CreationTime.Year.ToString());
Console::Write("Last access date: ");
Console::Write(fi->LastAccessTime.Month.ToString());
Console::Write(".{0}", fi->LastAccessTime.Day.ToString());
Console::WriteLine(".{0}", fi->LastAccessTime.Year.ToString());
return 0;
}