Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

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);
                }
            }
        }
Source by www.allenconway.net #
 
PREVIOUS NEXT
Tagged: #delete #files #directory
ADD COMMENT
Topic
Name
2+9 =