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 :: simple reset transform.rotation c# 
Csharp :: open url in c# 
Csharp :: asp.net c# write string to text file 
Csharp :: csgo throw last grenade bind 
Csharp :: C# open a new form 
Csharp :: get mouse position unity 
Csharp :: fade text unity 
Csharp :: save file with unique name c# 
Csharp :: unity how to set an objects postion x,y,z 
Csharp :: how to clear console in c# 
Csharp :: get max enum value c# 
Csharp :: c# windows grab screenshot 
Csharp :: play a sound c# 
Csharp :: c# for loop backwards 
Csharp :: unity textmeshpro 
Csharp :: c# convert dictionary to anonymous object 
Csharp :: unity reload current scene 
Csharp :: c# list string initialize inline 
Csharp :: remove repeated items in a list unity 
Csharp :: c# log to console 
Csharp :: c# print out 
Csharp :: wpf choose file dialog 
Csharp :: c# empty char 
Csharp :: how to draw text in monogame 
Csharp :: c# count specific element in list 
Csharp :: get type of exception c# 
Csharp :: Join Or Create Room() photon 
Csharp :: Exit string qoutes c# 
Csharp :: nepali phone number regex 
Csharp :: c# open file in default program 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =