In this article, we are going to cover how to create, delete and rename directory and also how to delete and rename the file.
Creating a Directory
We can create Directory using CreateDirectory() method present in the Directory class.
You will find the Directory with a given name at the specific location.
Renaming a Directory
You will find the updated Directory’s name at the specific location. There is no such method called Rename() so we are using the Move() method to rename a directory. Moving and renaming are the same operations in C#.
Deleting a Directory
You will find the Directory with a given name does not exist anymore at the specified location. If Directory is not empty, then Delete() will throw an exception because it deletes an only empty directory.
If we pass the extra parameters then the Delete() method is recursive. First, all the files and subdirectories of the specified directory are deleted before deleting the directory.
Renaming a File
You will find the changed file name at the specific location.
Deleting a File
You will find there is no such file exists with a given name at the specific location.
- Basics of File Handling in C#
- Basic Database Operations Using C#
- Check if a path has a file name extension in C#
- Default Interface Methods in C# 8.0
- Hello World Program : First program while learning Programming
- Range and Indices in C# 8.0
- Range Structure in C# 8.0
- Check if the given ranges are equal or not in C#
- How to Create a Range to a Specified End in C#?
- How to Create a Range From a Specified Start in C#?
- Getting the Hash Code of the Specified Range in C#
- Range Constructor in C#
- Finding the Start Index of the Specified Range in C#
- Finding the End Index of the Specified Range in C#
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.