CK.Text.Tests.TestHelper.DeleteFolder C# (CSharp) Method

DeleteFolder() public static method

public static DeleteFolder ( string directoryPath, bool recreate = false ) : void
directoryPath string
recreate bool
return void
        public static void DeleteFolder( string directoryPath, bool recreate = false )
        {
            int tryCount = 0;
            for( ; ; )
            {
                try
                {
                    if( Directory.Exists( directoryPath ) ) Directory.Delete( directoryPath, true );
                    if( recreate )
                    {
                        Directory.CreateDirectory( directoryPath );
                        File.WriteAllText( Path.Combine( directoryPath, "TestWrite.txt" ), "Test write works." );
                        File.Delete( Path.Combine( directoryPath, "TestWrite.txt" ) );
                    }
                    return;
                }
                catch( Exception ex )
                {
                    if( ++tryCount == 20 ) throw;
                    Console.WriteLine( "{1} - While cleaning up directory '{0}'. Retrying.", directoryPath, ex.Message );
                    System.Threading.Thread.Sleep( 100 );
                }
            }
        }