The FileInfo classes are derived from the MarshaByRefObject class. This permits to transfer the objects of FileInfo class across applications.The FileSystemInfo & FileInfo classes are defined in System.IO namespace.
The first thing that we can do with files is find out the information about it. Consider the following program for finding out the information.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO ;
class Class1
{
static void Main(string[] args)
{
FileInfo f1 = new FileInfo (@"c:\file1.txt");
Console.WriteLine ( "File name is : " + f1.Name );
Console.WriteLine ( "In Folder : " + f1.Directory ) ;
Console.WriteLine ( "Full name is : " + f1.FullName ) ;
Console.WriteLine ( "Last Write Time : " + f1.LastWriteTime.ToString() ) ;
Console.WriteLine ("Length : " + f1.Length ) ;
Console.WriteLine ("Creation Time : " + f1.CreationTime ) ;
Console.WriteLine ("Last access Time : " + f1.LastAccessTime ) ;
Console.WriteLine ("Attributes : " + f1.Attributes ) ;
}
}
Output:
File name is : file1.txt
In Folder : c:\
Full name is : c:\file1.txt
Last Write Time : 10/2/2001 1:25:21 PM
Length : 12
Creation Time : 10/2/2001 1:25:09 PM
Last access Time : 10/2/2001 1:25:31 PM
Attributes : Archive
Bookmarks