Пример #1
0
        public static async Task <TryResult> TryDeleteAsync(string path)
        {
            Exception exception = null;

            try { await AsyncFile.DeleteAsync(path); }
            catch (Exception ex) { exception = ex; }

            return(new TryResult(!File.Exists(path), exception));
        }
Пример #2
0
        public static async Task <bool> TryAndRetryDeleteAsync(string path, int times = 10, int delay = 50, bool throwEx = true, Action middleAction = null, Task middleTask = null)
        {
            if (!File.Exists(path))
            {
                return(true);
            }
            await Threading.MultipleAttempts(AsyncFile.DeleteAsync(path), times, delay, throwEx, middleAction, middleTask);

            return(!File.Exists(path));
        }
Пример #3
0
 public static async Task DeleteAsync(string path)
 {
     foreach (string dir in Directory.EnumerateDirectories(path))
     {
         await DeleteAsync(dir);
     }
     foreach (string file in Directory.EnumerateFiles(path))
     {
         await AsyncFile.DeleteAsync(file);
     }
 }
Пример #4
0
            public async Task Default_FileDeleted()
            {
                var contents = Enumerable.Repeat("This is a test line.", 150).ToList();
                var path     = Path.Combine(deleteTestFolder, nameof(Default_FileDeleted));


                Directory.CreateDirectory(deleteTestFolder);
                File.WriteAllLines(path, contents);

                await AsyncFile.DeleteAsync(path);

                Assert.IsFalse(File.Exists(path));
            }