Visual C++ .NET/File Directory/FileInfo

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Does a file exist

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    FileInfo ^fileinfo = gcnew FileInfo("c:\\a.txt");
    if (!fileinfo->Exists)
    {
        Console::WriteLine("File Not Found");
        return -1;
    }
}


Get file attributes

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    FileInfo ^fileinfo = gcnew FileInfo("c:\\a.txt");
    Console::WriteLine("Attributes: {0}", fileinfo->Attributes);
}


Get file creation time

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    FileInfo ^fileinfo = gcnew FileInfo("c:\\a.txt");
    Console::WriteLine("Created:    {0} {1}", 
        fileinfo->CreationTime.ToShortDateString(),
        fileinfo->CreationTime.ToLongTimeString());
}


Get file last access time

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    FileInfo ^fileinfo = gcnew FileInfo("c:\\a.txt");
    Console::WriteLine("Accessed:   {0} {1}", 
        fileinfo->LastAccessTime.ToShortDateString(),
        fileinfo->LastAccessTime.ToLongTimeString());
}


Get file last write time

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    FileInfo ^fileinfo = gcnew FileInfo("c:\\a.txt");
    Console::WriteLine("Updated:    {0} {1}", 
        fileinfo->LastWriteTime.ToShortDateString(),
        fileinfo->LastWriteTime.ToLongTimeString());
}


Get file length

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    FileInfo ^fileinfo = gcnew FileInfo("c:\\a.txt");

    Console::WriteLine("Length:     {0}", fileinfo->Length);
}


Get the full name of a file

 
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main(array<System::String ^> ^args)
{
    FileInfo ^fileinfo = gcnew FileInfo("c:\\a.txt");
    Console::WriteLine("Name:       {0}", fileinfo->FullName);
}