//path là đường dấn của file đổi tên, newname là tên mới ko gồm đuôi public static void Rename(string path, string newname) { if (File.Exists(path)) { string rootpath = XPath.DirRoot_Info(path); string ext = XPath.GetExtention(path); string newpath = rootpath + "\\" + newname + ext; Move(path, newpath); } }
//Lấy ảnh từ resources dựa theo đuôi của đường dẫn public static Image LoadImagebyExt(string path) { //lấy ra đuôi của đường dẫn if (System.IO.File.Exists(path)) { if (System.IO.File.GetAttributes(path).HasFlag(System.IO.FileAttributes.Directory)) { return(Properties.Resources.folder); } } string ext = XPath.GetExtention(path); switch (ext) { case ".txt": return(Properties.Resources.txt); case ".pdf": return(Properties.Resources.pdf); case ".doc": return(Properties.Resources.doc); case ".docx": return(Properties.Resources.docx); case ".xls": return(Properties.Resources.xls); case ".xlsx": return(Properties.Resources.xlsx); case ".exe": return(Properties.Resources.exe); case ".jpeg": return(Properties.Resources.jpeg); case ".png": return(Properties.Resources.png); default: break; } return(Properties.Resources.file); }
//so sánh đuôi file trong path vs ext,ext chứa đuôi cần so sánh public static bool IsEqualExt(string path, string ext) { ext = ext.ToLower(); if (!ext.Contains(".")) { ext = "." + ext; } if (XPath.GetExtention(path) == null) { return(false); } else if (XPath.GetExtention(path).Equals(ext, StringComparison.CurrentCultureIgnoreCase)) { return(true); } else { return(false); } }
//so sánh đuôi file trong path vs ext,ext chứa các đuôi cần so sánh public static bool IsEqualExt(string path, string[] ext) { if (XPath.GetExtention(path) == null) { return(false); } bool check = false; //lấy ra từng đuôi một để so sánh for (int i = 0; i < ext.Length; i++) { //thêm dấu chấm vs chuyển thành chữ thường đề phòng if (!ext[i].Contains(".")) { ext[i] = "." + ext[i]; } if (XPath.GetExtention(path).Equals(ext[i], StringComparison.CurrentCultureIgnoreCase)) { return(true); // nếu tm 1 đuôi trong chỗ đuỗi thi thoát } } return(check); }