using System; using System.IO; using System.Windows.Forms; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ClassLibrary { public class Helper { public static bool IsValidPath(string path, bool allowRelativePaths = false) { bool isValid = true; try { string fullPath = Path.GetFullPath(path); if (allowRelativePaths) { isValid = Path.IsPathRooted(path); } else { string root = Path.GetPathRoot(path); isValid = string.IsNullOrEmpty(root.Trim(new char[] { '\\', '/' })) == false; } } catch (Exception ex) { isValid = false; } return isValid; } public static string CreateOutDir(string dirName) { string outDirName = dirName + "\\TEST\\"; bool isValid = IsValidPath(outDirName); if (isValid == false) return ""; try { if (!Directory.Exists(outDirName)) { Directory.CreateDirectory(outDirName); } } catch (Exception ex) { isValid = false; MessageBox.Show( ex.Message, "Exception!", //Resources.System_Error_Message_Title, MessageBoxButtons.OK, MessageBoxIcon.Error); } return outDirName; } public static string FoundPicExt(string[] filesname) { string ext = ""; for (int i = 0; i < filesname.Length; i++) { if (Path.GetExtension(filesname[i]) == ".bmp" || Path.GetExtension(filesname[i]) == ".png" || Path.GetExtension(filesname[i]) == ".jpg" || Path.GetExtension(filesname[i]) == ".tif") { ext = Path.GetExtension(filesname[i]); return ext; } } return ext; } public static string[] LoadRakurseFiles(string path) { //string path = txtSourceFilePath.Text; string[] _rakurseFiles = null; try { // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(path); if (attr.HasFlag(FileAttributes.Directory)) { string[] filesname = Directory.GetFiles(path); //!!!!Nick string ext = FoundPicExt(filesname); //!!!!Nick ext = "*" + ext; //Path.GetExtension(filesname[2]); //!!!!Nick var files = Directory.GetFiles(path, ext).ToList(); //!!!!Nick //var files = Directory.GetFiles(path, "*.tif").ToList(); //.OrderBy(f => f.CreationTime); files.Sort(); //txtNFilesSelected.Text = files.Count.ToString(); _rakurseFiles = new string[files.Count]; files.CopyTo(_rakurseFiles); } } catch (Exception ex) { //this.ShowErrorMessage(ex); } return _rakurseFiles; } } }