Created
April 15, 2014 13:44
-
-
Save Seregamil/10733933 to your computer and use it in GitHub Desktop.
Deleting files by mask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Молодец