How to Extract Files and their Information

It is very crucial to work on file system. If you are developer and developing such an application like FTP application then it becomes more crucial. You have to provide easy access to file system as "My Computer" support. If the user wants to change directory, make a new directory within directories or to be accessed files of specific directory then the application should support it.

There are many ways to develop such application which provides functionality like "My Computer". There is only difference is environment that how provides functionality to the user. There are following two mechanisms;

  1. Microsoft's VB6 component [Microsoft.VisualBasic.Compatibility.VB6]

    a. DriveListBox
    b. DirListBox
    c. FileListBox
     
  2. OpenFileDialog - This dialoag provides to access file system however you can only access one file along with full path.
     
  3.  FolderBrowserDialog - This dialog provides the user to be accessed files like "My Computer". The user gets a drive dialog and choose the appropriate folder. After selection, the user gets a full folder path which keeps all files that can be extracted using System.IO classes. The user can also be created a new folder within directories [Using in this artical].

Now, we have a folder path, so, our next task is to be extracted files and their information and display them. There are various "System.IO" classes in which I am using only two classes;

  • Directory
  • FileInfo.

Directory.GetFiles() - it is Directory class function which takes single string parameter to extract all files name along with their full path.

Then each extracted file is given "to FileInfo" object [to be initialized for each file]. The object extracts all file information. There are many properties and functions that provide file information, however, we are using only following properties;
|
.Name - Provides the file name.
.Extension - Provides the file extension as file type
.Length - Shows the file size that is long type
.CreationTime - Provides the file creation date and time.
.LastAccessTime - Provides the file last access date and time.

After extrating all information of the file, to being displayed in Listview. You can find source code as well. 

Up Next
    Ebook Download
    View all
    Learn
    View all