在这里我们粗暴的黑客.我喜欢它是递归的.在遇到Windows通配符的缺点后,我可能会决定使用正则表达式,而不是让GetFiles()为我做.
using System.IO; public static string[] ExpandFilePaths(string[] args) { var fileList = new List(); foreach (var arg in args) { var substitutedArg = System.Environment.ExpandEnvironmentVariables(arg); var dirPart = Path.GetDirectoryName(substitutedArg); if (dirPart.Length == 0) dirPart = "."; var filePart = Path.GetFileName(substitutedArg); foreach (var filepath in Directory.GetFiles(dirPart, filePart)) fileList.Add(filepath); } return fileList.ToArray(); }