test/Shared/FunctionalTests.Transitional/TestHelpers/IOHelpers.cs
/// <summary>
/// Safely deletes the directory and ignores any access violation exceptions.
/// </summary>
/// <param name="path"> The directory to delete. </param>
Safely deletes the directory and ignores any access violation exceptions.
Safely deletes the directory and ignores any access violation exceptions .
[SecuritySafeCritical]
        [PermissionSet(SecurityAction.Assert, Unrestricted = true)]
        [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Need to catch everything here.")]
        public static void SafeDeleteDirectory(string path)
        {
            for (var i = 0; i < 3; ++i)
            {
                try
                {
                    Directory.Delete(path, true);
                    return;
                }
                catch (Exception)
                {
                }
                Thread.Sleep(500);
                try
                {
                    foreach (var file in Directory.GetFiles(path, "*", SearchOption.AllDirectories))
                    {
                        SafeDeleteFile(file);
                    }
                    return;
                }
                catch (Exception)
                {
                }
                Thread.Sleep(500);
            }
        }
[ SecuritySafeCritical ] [ PermissionSet ( SecurityAction . Assert , Unrestricted = true ) ] [ SuppressMessage ( " " , " " , Justification = " " ) ] public static void SafeDeleteDirectory ( string path ) { for ( var i = 0 ; i < 3 ; ++ i ) { try { Directory . Delete ( path , true ) ; return ; } catch ( Exception ) { } Thread . Sleep ( 500 ) ; try { foreach ( var file in Directory . GetFiles ( path , " " , SearchOption . AllDirectories ) ) { SafeDeleteFile ( file ) ; } return ; } catch ( Exception ) { } Thread . Sleep ( 500 ) ; } }
Safely deletes the directory and ignores any access violation exceptions.
Safely deletes the directory and ignores any access violation exceptions .
// Calling Directory.Delete demands FileIOPermission (Write flag) for the specified path. // try different ways of contents of directory, fail after 3 attempts
path
string
The directory to delete.
The directory to delete .