FileHelper.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. string folderName = a_strPathName.Substring(0, a_strPathName.LastIndexOf("\\"));
  14. //DirectoryInfo d = new DirectoryInfo(a_strPathName);
  15. //return d.FullName;
  16. return folderName;
  17. // string aFirstName = aFile.Substring(aFile.LastIndexOf("\\") + 1, (aFile.LastIndexOf(".") - aFile.LastIndexOf("\\") - 1)); //文件名
  18. // string aLastName = aFile.Substring(aFile.LastIndexOf(".") + 1, (aFile.Length - aFile.LastIndexOf(".") - 1)); //扩展名
  19. // string strFilePaht = "文件路径";
  20. // Path.GetFileNameWithoutExtension(strFilePath); 这个就是获取文件名的
  21. // //还有的就是用Substring截取
  22. // strFilePaht.Substring(path.LastIndexOf("\\") + 1, path.Length - 1 - path.LastIndexOf("\\"));
  23. // strFilePaht.Substring(path.LastIndexOf("."), path.Length - path.LastIndexOf("."));
  24. // //或者用openFileDialog1.SafeFileName
  25. // //这样就能取到该文件的所在目录路径
  26. //string path1 = System.IO.Path.GetDirectoryName(openFileDialog1.FileName) + @"\";
  27. // string path = Path.GetFileName("C:\My Document\path\image.jpg"); //只获取文件名image.jpg
  28. }
  29. }
  30. }