Skip to content

Instantly share code, notes, and snippets.

@Seregamil Seregamil/Program.cs
Created Apr 15, 2014

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

Salvacore commented Apr 16, 2014

Молодец

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.