Windows directory access

Posted by

Directory access with CSharp

Windows Directory access with C# in .Net is done by using the following classes:


The FileInfo and DirectoryInfo classes display instances to these classes that consist of whole lot of information for opening, closing, moving, and deleting files and folders. You can create instances of these classes using string that represents the name of the file, folder or drive in to the constructor.
Performing windows related tasks will put us into System Programming area and in this field, you can enjoy luxurious life if you become a keen and efficient developer.Let us see that how we can define system programming:

System programming (or systems programming) is the activity of computer programming system software. The primary distinguishing characteristic of systems programming when compared to application programming is that application programming aims to produce software which provides services to the user (e.g. word processor), whereas systems programming aims to produce software which provides services to the computer hardware (e.g. disk defragmenter). It requires a greater degree of hardware awareness.


Below is the program that shows different attributes of files in folder

class Program
static void Main(string[] args)

/* DirectoryInfo is an instance of a class that provides information about a specific directory.
* So for example if you wanted the information about D:\MyFolder */

DirectoryInfo directoryObject = new DirectoryInfo(@”d:\Downloads”);

/* FileInfo provides operations on properties and instance methods for the basic file systems.
This is not inherited class.We are using this class as an indexer to get the list of the files in the directory*/
FileInfo[] fileList = directoryObject.GetFiles();

foreach (FileInfo fileObject in fileList)
Console.WriteLine(“File Name: {0} Rank: {1} Length: {2}”,
fileObject.Name, fileList.Rank, fileList.Length);


Facebook Comments

Syed Adeel Ahmed
Analyst, Programmer, Educationist and Blogger at Technofranchise
Computer Systems Engineer from Sir Syed University Of Engineering & Technology.I am passionate about all types of programming.
Syed Adeel Ahmed on FacebookSyed Adeel Ahmed on GoogleSyed Adeel Ahmed on InstagramSyed Adeel Ahmed on Twitter