FileHelper.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace OTSModelSharp.ServiceInterface
  8. {
  9. public static class FileHelper
  10. {
  11. public static string GetFolderName(string a_strPathName)
  12. {
  13. if (a_strPathName == "Untitled")
  14. {
  15. return null;
  16. }
  17. string folderName = a_strPathName.Substring(0, a_strPathName.LastIndexOf("\\"));
  18. //DirectoryInfo d = new DirectoryInfo(a_strPathName);
  19. //return d.FullName;
  20. return folderName;
  21. // string aFirstName = aFile.Substring(aFile.LastIndexOf("\\") + 1, (aFile.LastIndexOf(".") - aFile.LastIndexOf("\\") - 1)); //文件名
  22. // string aLastName = aFile.Substring(aFile.LastIndexOf(".") + 1, (aFile.Length - aFile.LastIndexOf(".") - 1)); //扩展名
  23. // string strFilePaht = "文件路径";
  24. // Path.GetFileNameWithoutExtension(strFilePath); 这个就是获取文件名的
  25. // //还有的就是用Substring截取
  26. // strFilePaht.Substring(path.LastIndexOf("\\") + 1, path.Length - 1 - path.LastIndexOf("\\"));
  27. // strFilePaht.Substring(path.LastIndexOf("."), path.Length - path.LastIndexOf("."));
  28. // //或者用openFileDialog1.SafeFileName
  29. // //这样就能取到该文件的所在目录路径
  30. //string path1 = System.IO.Path.GetDirectoryName(openFileDialog1.FileName) + @"\";
  31. // string path = Path.GetFileName("C:\My Document\path\image.jpg"); //只获取文件名image.jpg
  32. }
  33. }
  34. }