Beispiel #1
0
        public void DeleteFile(string path, DeletionOptions options)
        {
            options = options ?? DeletionOptions.TryThreeTimes;

            if (StringHelper.IsNullOrWhiteSpace(path))
            {
                return;
            }

            for (var i = 0; i < options.RetryAttempts; i++)
            {
                try
                {
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                }
                catch
                {
                    Thread.Sleep(options.SleepBetweenAttemptsMilliseconds);

                    if (i == options.RetryAttempts - 1)
                    {
                        if (options.ThrowOnFailure)
                        {
                            throw;
                        }

                        break;
                    }
                }
            }
        }
Beispiel #2
0
        public void PurgeDirectory(string targetDirectory, Predicate <IFileInfo> include, DeletionOptions options)
        {
            if (!DirectoryExists(targetDirectory))
            {
                return;
            }

            foreach (var file in EnumerateFilesRecursively(targetDirectory))
            {
                if (include != null)
                {
                    var info = new FileInfoAdapter(new FileInfo(file));
                    if (!include(info))
                    {
                        continue;
                    }
                }

                DeleteFile(file, options);
            }
        }
Beispiel #3
0
 public void PurgeDirectory(string targetDirectory, DeletionOptions options)
 {
     PurgeDirectory(targetDirectory, (fi) => true, options);
 }