public static string CheckExtension() { var selectExtension = SystemConsole.GetInputStr("请输入文件后缀[如\"cs,cpp\"]:"); return((string.IsNullOrEmpty(selectExtension) || selectExtension == "*.*") ? "*.*" : string.Join("|", selectExtension.Split(',', '|').Select(p => "." + p.TrimStart('*').TrimStart('.')).ToArray())); }
public static List <string> CheckPath(string selectExtension = "*.*", SearchOption searchOption = SearchOption.AllDirectories) { if (string.IsNullOrEmpty(selectExtension)) { selectExtension = SystemConsole.GetInputStr("请输入文件后缀 ('.cs'):"); } var selectExtensions = (string.IsNullOrEmpty(selectExtension) || selectExtension == "*.*") ? new string[0] : selectExtension.Split(',', '|').Select(p => "." + p.TrimStart('*').TrimStart('.')).ToArray(); string path = SystemConsole.GetInputStr( beforeTip: string.Format("请拖入文件夹或文件({0}):", selectExtension), afterTip: "您选择的文件夹或文件:"); List <string> files = new List <string>(); if (string.IsNullOrEmpty(path)) { return(files); } InputPath = path.Replace("\\", "/").TrimEnd('/'); if (Directory.Exists(path)) { files.AddRange(DirectoryHelper.GetFiles(path, selectExtensions, searchOption)); } else if (File.Exists(path)) { if (selectExtensions.Contains(Path.GetExtension(path))) { files.Add(path); } if (selectExtensions.Length == 0) { files.Add(path); } } else { Console.WriteLine("path is not valid!"); } files.Sort(); return(files.Select(p => p.Replace("\\", "/")).ToList()); }