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

How to delete folder with files on c#

Directory.Delete(@"folderPath", 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 :: c# get set value 
Csharp :: jump in unity 
Csharp :: c# listbox delete selected items 
Csharp :: c# string array to string 
Csharp :: unity 2d movement 
Csharp :: c# declare an int list 
Csharp :: c# regex get matched string 
Csharp :: clear controls from panel c# 
Csharp :: smtp check if email sent 
Csharp :: bytes to httppostedfilebase c# 
Csharp :: c# if statement one line 
Csharp :: c# using file.io 
Csharp :: check if animation is playing unity 
Csharp :: send type as argument c# 
Csharp :: unity check if other object is colliding 
Csharp :: serilog set log level 
Csharp :: linq from select 
Csharp :: linq where id in list 
Csharp :: c# csv read write 
Csharp :: c# underscore variable 
Csharp :: c# lambda join two tables 
Csharp :: unity round float to nearest 10 
Csharp :: how to create a delegate in c# 
Csharp :: unity call function on animation finish 
Csharp :: how to convert date to Complete ISO-8601 date in c# 
Csharp :: upgrade asp.net core to 5.0 
Csharp :: get index c# 
Csharp :: unity print vs debug log 
Csharp :: how to open onscreen keyboard c# 
Csharp :: destroy the game object if the animator has finished its animation 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =