FilePathParser.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Namespace: System.Web.Utils
  3. * Class: FilePathParser
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: ??%
  10. *
  11. * (C) Gaurav Vaish (2001)
  12. */
  13. namespace System.Web.Utils
  14. {
  15. internal class FilePathParser
  16. {
  17. private static char[] pathSeparators = {
  18. Path.DirectorySeparatorChar,
  19. Path.AltDirectorySeparatorChar
  20. };
  21. private string dirName;
  22. private string fileName;
  23. private string shortDirName;
  24. private string shortFileName;
  25. private bool exists;
  26. public FilePathParser(string path, bool isFile, bool getShortNames)
  27. {
  28. path = path.Trim();
  29. if(Path.GetPathRoot(path).Length < path.Length)
  30. {
  31. path = path.TrimEnd(pathSeparators);
  32. }
  33. if(!isFile)
  34. {
  35. dirName = GetBaseDirOrRoot(path);
  36. } else
  37. {
  38. dirName = path;
  39. }
  40. if(getShortNames)
  41. {
  42. if(!Directory.Exists(dirName))
  43. {
  44. dirName = null;
  45. return;
  46. }
  47. shortDirName = GetShortPathName(dirName);
  48. if(shortDirName==null)
  49. {
  50. dirName = null;
  51. return;
  52. }
  53. if(shortDirName == dirName)
  54. {
  55. shortDirName = null;
  56. } else
  57. {
  58. throw new NotImplementedException();
  59. }
  60. }
  61. }
  62. public static string GetBaseDirOrRoot(string file)
  63. {
  64. string bDir = Path.GetDirectoryName(file);
  65. return ( bDir!=null ? bDir : GetPathRoot(file));
  66. }
  67. public static string GetShortPathName(string path)
  68. {
  69. //TODO: Native calls required, it's in kernel32.dll for windows
  70. throw new NotImplementedException();
  71. }
  72. }
  73. }