Skip to content

Instantly share code, notes, and snippets.

@Seregamil
Created April 15, 2014 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Seregamil/10733933 to your computer and use it in GitHub Desktop.
Save Seregamil/10733933 to your computer and use it in GitHub Desktop.
Deleting files by mask
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace maskFiles
{
class Program
{
static void Main(string[] args)
{
start: Console.WriteLine("Введите расширение файла.");
Console.WriteLine("Пример: \".txt\":");
string mask = Console.ReadLine();
if (mask.Length == 0) goto start;
if (mask[0] != '.') goto start;
string[] fileNames = Directory.GetFiles(Environment.CurrentDirectory, "*" + mask, SearchOption.AllDirectories);
if (fileNames.Length == 0) goto start;
string fileErrors = string.Empty;
int j = 0;
for ( ; j != fileNames.Length; j++)
{
try
{
File.Delete(fileNames[j]);
Console.WriteLine("Файл " + fileNames[j] + " успешно удален.");
}
catch
{
fileErrors = fileErrors + "\n" + filenames[j];
}
}
if (fileErrors != string.Empty)
{
Console.WriteLine("Файлы, с которыми произошли проблемы при удалении: ");
Console.WriteLine(fileErrors);
}
else
{
Console.WriteLine("Процедура удаления прошла успешно!");
}
goto start;
}
}
}
@Salvacore
Copy link

Молодец

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment