Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

how to delete all files in a directory c#

System.IO.DirectoryInfo di = new DirectoryInfo("YourPath");

foreach (FileInfo file in di.GetFiles())
{
    file.Delete(); 
}
foreach (DirectoryInfo dir in di.GetDirectories())
{
    dir.Delete(true); 
}
Comment

delete all dir content c#

 new System.IO.DirectoryInfo(@"C:Temp").Delete(true);

 //Or

 System.IO.Directory.Delete(@"C:Temp", true);
Comment

C# delete folder with all contents

System.IO.Directory.Delete("C:TempTest", True)
Comment

c# how to delete all files in directory

		/// <summary>
        /// Delete all files inside a directory
        /// </summary>
        /// <param name="filePath">Directory Path</param>
		Using System.IO;
        public static void DeleteFiles(string filePath)
        {
            if (!Directory.Exists(filePath))
            {
                throw new Exception("Directory not exist");
            }

            string[] existingFiles = Directory.GetFiles(filePath);
            if (existingFiles.Length > 0)
            {
                foreach (var item in existingFiles)
                {
                    File.Delete(item);
                }
            }
        }
Comment

PREVIOUS NEXT
Code Example
Csharp :: dictionary c# 
Csharp :: object to mouse unity 
Csharp :: unity object to mouse 
Csharp :: blazor button onclick parameter 
Csharp :: visual studio run multiple forms at once 
Csharp :: c# search on google 
Csharp :: unity get child 
Csharp :: c# get random double in range 
Csharp :: c# console play sound 
Csharp :: includes method C# 
Csharp :: c sharp split string 
Csharp :: c# solution path 
Csharp :: c# shuffle array 
Csharp :: get directory name of path c# 
Csharp :: c# winforms textbox cursor position 
Csharp :: unity change tmp text from script 
Csharp :: lat long data type c# 
Csharp :: start command line from c# 
Csharp :: consecutive numbers c# 
Csharp :: c# append textbox 
Csharp :: c# string array initialization 
Csharp :: color picker wpf 
Csharp :: c# object to dictionary 
Csharp :: c# find duplicates in list of strings 
Csharp :: Find an item in a list by LINQ 
Csharp :: get random color 32 
Csharp :: how to access individual characters in a string in c# 
Csharp :: c# search string array 
Csharp :: c# return switch 
Csharp :: check if animation is playing unity 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =