SlideShare a Scribd company logo
Directory Class
in
C #
Directories….
Telephone directory….??
Directory Class in C #
Let’s See….
Directory Class
1. Deals with Directories and Sub-Directories.
2. Using System.IO
3. Static in Nature.
4. No Instantiation Required.
5. It Cannot be Inherited.
Methods:
Name Description
CreateDirectory(String) Creates all directories and subdirectories in the specified
path unless they already exist.
CreateDirectory(String,
DirectorySecurity)
Creates all the directories in the specified path, unless
the already exist, applying the specified Windows
security.
Delete(String) Deletes an empty directory from a specified path.
Delete(String, Boolean) Deletes the specified directory and, if indicated, any
subdirectories and files in the directory.
EnumerateDirectories(String) Returns an enumerable collection of directory names in a
specified path.
Exists Determines whether the given path refers to an existing
directory on disk.
Move Moves a file or a directory and its contents to a new
location.
GetCurrentDirectory Gets the current working directory of the application.
SetCurrentDirectory Sets the application's current working directory to the
specified directory.
GetLastAccessTime Returns the date and time the specified file or directory
was last accessed.
Remarks:
 Efficient to perform One directory-related action.
 The static methods of the Directory class perform security
checks on all methods.
 Make Use of DirectoryInfo instance methods if we want to
reuse objects several times.
 The security check will not always be necessary.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading.Tasks;
namespace DirectoryExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("n**************************************************
*******n");
Console.WriteLine("tt DIRECTORY EXAMPLE:");
Console.WriteLine("n**************************************************
*******n");
if (Directory.Exists("c:testDir1"))
{
//Shows Message If testdir1 Exists
Console.WriteLine("t Directory 'testDir' Exist ");
}
else
{
// Create The Directory testDir1
Directory.CreateDirectory("C:TestDir1");
Console.WriteLine("t Directory: TestDir1 Created....!!n");
// Create The Directory testDir2
Directory.CreateDirectory("C:TestDir1TestDir2");
Console.WriteLine("t Directory: TestDir2 Created....!!n");
// Move The Directory testDir2 As testDir in c:
Directory.Move("C:TestDir1TestDir2", "C:TestDir");
Console.WriteLine("t Directory: TestDir2 Moved....!!n");
// Delete The Directory testDir1
Directory.Delete("C:TestDir1", true);
Console.WriteLine("t Directory: TestDir1 Deleted....!!n");
}
Console.WriteLine("n***************************************************
******n");
Console.ReadKey();
}
}
}
************************************************
DIRECTORY EXAMPLE
************************************************
Directory: TestDir1 Created....!!
Directory: TestDir2 Created....!!
Directory: TestDir2 Moved....!!
Directory: TestDir1 Deleted....!!
************************************************
Output:
Questions….??
Thank You….

More Related Content

PPTX
19 reflection
PDF
Java Inner Classes
PPTX
Java- Nested Classes
DOCX
Lecture22.23.07.2014
PPT
Inner classes ,annoumous and outer classes in java
DOCX
Nested classes in java
PPTX
Inner classes
PPTX
Destructer
19 reflection
Java Inner Classes
Java- Nested Classes
Lecture22.23.07.2014
Inner classes ,annoumous and outer classes in java
Nested classes in java
Inner classes
Destructer

What's hot (9)

PPTX
Inner Classes & Multi Threading in JAVA
PPTX
Inner class
PPTX
Java - User Defined classes
PPTX
Java Inner Class
PPT
L5 classes, objects, nested and inner class
PDF
Classes and Nested Classes in Java
PPTX
15reflection in c#
PPTX
Windows controls in c
PDF
Open Harvester - Search publications for a researcher from CrossRef, PubMed a...
Inner Classes & Multi Threading in JAVA
Inner class
Java - User Defined classes
Java Inner Class
L5 classes, objects, nested and inner class
Classes and Nested Classes in Java
15reflection in c#
Windows controls in c
Open Harvester - Search publications for a researcher from CrossRef, PubMed a...
Ad

Similar to C# Directory class in c# (20)

PDF
Intake 37 11
PDF
Intake 38 10
PPT
Chapter 5 Class File
PDF
Recursively Searching Files and DirectoriesSummaryBuild a class .pdf
PDF
130614 sebastiano panichella - mining source code descriptions from develo...
PDF
PPTX
C# File IO Operations
PPTX
C# classes objects
PDF
My History
PPT
Object and Classes in Java
PPT
intro unix/linux 07
PPT
4.file service architecture (1)
PPT
4.file service architecture
PPT
classandobjectunit2-150824133722-lva1-app6891.ppt
PPTX
Slide 1.-datastructure
PPTX
oop lecture 3
PPS
09 iec t1_s1_oo_ps_session_13
PPTX
Chapter 2 Linux File System and net.pptx
PDF
OOP, Networking, Linux/Unix
PPT
ASP.NET Session 7
Intake 37 11
Intake 38 10
Chapter 5 Class File
Recursively Searching Files and DirectoriesSummaryBuild a class .pdf
130614 sebastiano panichella - mining source code descriptions from develo...
C# File IO Operations
C# classes objects
My History
Object and Classes in Java
intro unix/linux 07
4.file service architecture (1)
4.file service architecture
classandobjectunit2-150824133722-lva1-app6891.ppt
Slide 1.-datastructure
oop lecture 3
09 iec t1_s1_oo_ps_session_13
Chapter 2 Linux File System and net.pptx
OOP, Networking, Linux/Unix
ASP.NET Session 7
Ad

More from Prem Kumar Badri (20)

PPTX
Module 15 attributes
PPTX
Module 14 properties and indexers
PPTX
Module 12 aggregation, namespaces, and advanced scope
PPTX
Module 13 operators, delegates, and events
PPTX
Module 11 : Inheritance
PPTX
Module 10 : creating and destroying objects
PPTX
Module 9 : using reference type variables
PPTX
Module 8 : Implementing collections and generics
PPTX
Module 7 : Arrays
PPTX
Module 6 : Essentials of Object Oriented Programming
PPTX
Module 5 : Statements & Exceptions
PPTX
Module 4 : methods & parameters
PPTX
Module 3 : using value type variables
PPTX
Module 2: Overview of c#
PPTX
Module 1 : Overview of the Microsoft .NET Platform
PPTX
C# Non generics collection
PPTX
C# Multi threading
PPT
C# Method overloading
PPTX
C# Inheritance
PPTX
C# Generic collections
Module 15 attributes
Module 14 properties and indexers
Module 12 aggregation, namespaces, and advanced scope
Module 13 operators, delegates, and events
Module 11 : Inheritance
Module 10 : creating and destroying objects
Module 9 : using reference type variables
Module 8 : Implementing collections and generics
Module 7 : Arrays
Module 6 : Essentials of Object Oriented Programming
Module 5 : Statements & Exceptions
Module 4 : methods & parameters
Module 3 : using value type variables
Module 2: Overview of c#
Module 1 : Overview of the Microsoft .NET Platform
C# Non generics collection
C# Multi threading
C# Method overloading
C# Inheritance
C# Generic collections

Recently uploaded (20)

PDF
Classroom Observation Tools for Teachers
PDF
Complications of Minimal Access Surgery at WLH
PDF
Computing-Curriculum for Schools in Ghana
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Pre independence Education in Inndia.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Insiders guide to clinical Medicine.pdf
Classroom Observation Tools for Teachers
Complications of Minimal Access Surgery at WLH
Computing-Curriculum for Schools in Ghana
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Anesthesia in Laparoscopic Surgery in India
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Final Presentation General Medicine 03-08-2024.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
Pre independence Education in Inndia.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
O7-L3 Supply Chain Operations - ICLT Program
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
01-Introduction-to-Information-Management.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
VCE English Exam - Section C Student Revision Booklet
Insiders guide to clinical Medicine.pdf

C# Directory class in c#

  • 3. Directory Class 1. Deals with Directories and Sub-Directories. 2. Using System.IO 3. Static in Nature. 4. No Instantiation Required. 5. It Cannot be Inherited.
  • 4. Methods: Name Description CreateDirectory(String) Creates all directories and subdirectories in the specified path unless they already exist. CreateDirectory(String, DirectorySecurity) Creates all the directories in the specified path, unless the already exist, applying the specified Windows security. Delete(String) Deletes an empty directory from a specified path. Delete(String, Boolean) Deletes the specified directory and, if indicated, any subdirectories and files in the directory. EnumerateDirectories(String) Returns an enumerable collection of directory names in a specified path.
  • 5. Exists Determines whether the given path refers to an existing directory on disk. Move Moves a file or a directory and its contents to a new location. GetCurrentDirectory Gets the current working directory of the application. SetCurrentDirectory Sets the application's current working directory to the specified directory. GetLastAccessTime Returns the date and time the specified file or directory was last accessed.
  • 6. Remarks:  Efficient to perform One directory-related action.  The static methods of the Directory class perform security checks on all methods.  Make Use of DirectoryInfo instance methods if we want to reuse objects several times.  The security check will not always be necessary.
  • 7. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Threading.Tasks; namespace DirectoryExample { class Program { static void Main(string[] args) { Console.WriteLine("n************************************************** *******n"); Console.WriteLine("tt DIRECTORY EXAMPLE:"); Console.WriteLine("n************************************************** *******n"); if (Directory.Exists("c:testDir1")) { //Shows Message If testdir1 Exists Console.WriteLine("t Directory 'testDir' Exist "); }
  • 8. else { // Create The Directory testDir1 Directory.CreateDirectory("C:TestDir1"); Console.WriteLine("t Directory: TestDir1 Created....!!n"); // Create The Directory testDir2 Directory.CreateDirectory("C:TestDir1TestDir2"); Console.WriteLine("t Directory: TestDir2 Created....!!n"); // Move The Directory testDir2 As testDir in c: Directory.Move("C:TestDir1TestDir2", "C:TestDir"); Console.WriteLine("t Directory: TestDir2 Moved....!!n"); // Delete The Directory testDir1 Directory.Delete("C:TestDir1", true); Console.WriteLine("t Directory: TestDir1 Deleted....!!n"); } Console.WriteLine("n*************************************************** ******n"); Console.ReadKey(); } } }
  • 9. ************************************************ DIRECTORY EXAMPLE ************************************************ Directory: TestDir1 Created....!! Directory: TestDir2 Created....!! Directory: TestDir2 Moved....!! Directory: TestDir1 Deleted....!! ************************************************ Output: