Exemplo n.º 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;
                    }
                }
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 3
0
 public void PurgeDirectory(string targetDirectory, DeletionOptions options)
 {
     PurgeDirectory(targetDirectory, (fi) => true, options);
 }