/// <summary>
/// c# 文件夹 递归访问
/// </summary>
using System;
using System.IO;
namespace DelAllLrcFiles
{
class Program
{
static
readonly string root = @"F:mymusicfiles";
static readonly string ext = ".lrc";
static void Main(string[] args)
{
DelAllLrc(root);
}
/// <summary>
/// 删除文件夹及子文件夹中的文件。
/// </summary>
static void DelAllLrc(string path)
{
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
if (file.EndsWith(ext, StringComparison.CurrentCultureIgnoreCase))
{
try
{
File.Delete(file);
}
catch
{
Console.WriteLine("出错了,文件:" + file);
}
}
}
string[] dirs = Directory.GetDirectories(path);
foreach (string dir in dirs)
{
DelAllLrc(dir);
}
}
}
}