GPFiles.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* ------------------------------------------------------------ */
  2. // Body of GPFiles interface.
  3. // This file implements the code of the GPFiles.cp file.
  4. // dwc August 1999. COOL version kjg May 2000
  5. // kjg September 2000. Stripped version as abstract base class.
  6. // kjg March 2001. Version for Beta-2 libraries.
  7. /* ------------------------------------------------------------ */
  8. namespace GPFiles {
  9. public abstract class GPFiles {
  10. private static bool unix = (System.Environment.NewLine == "\n");
  11. public static char pathSep = unix ? ':' : ';';
  12. public static char fileSep = unix ? '/' : '\\';
  13. public static char optChar = unix ? '-' : '/';
  14. /* ---------------------------------- */
  15. private static System.String mkStr(char[] arr) {
  16. int ix = 0;
  17. char ch;
  18. do {
  19. ch = arr[ix]; ix++;
  20. } while (ch != '\0');
  21. return new System.String(arr,0,ix-1);
  22. }
  23. private static char[] mkArr(System.String str) {
  24. char[] rslt = new char[str.Length + 1];
  25. str.CopyTo(0, rslt, 0, str.Length);
  26. rslt[str.Length] = '\0';
  27. return rslt;
  28. }
  29. /* ---------------------------------- */
  30. public static bool isOlder(FILE first, FILE second) {
  31. int comp = System.DateTime.Compare(
  32. System.IO.File.GetLastWriteTime(first.path),
  33. System.IO.File.GetLastWriteTime(second.path)
  34. );
  35. return comp == -1;
  36. }
  37. public static void MakeDirectory(char[] dirName) {
  38. System.String path = mkStr(dirName);
  39. System.IO.Directory.CreateDirectory(path);
  40. }
  41. public static char[] CurrentDirectory() {
  42. return mkArr(System.IO.Directory.GetCurrentDirectory());
  43. }
  44. public static bool exists(char[] filName) {
  45. System.String path = mkStr(filName);
  46. return System.IO.File.Exists(path);
  47. }
  48. public static char[][] FileList(char[] dirPath) {
  49. string dirStr = mkStr(dirPath);
  50. string[] files = System.IO.Directory.GetFiles(dirStr);
  51. if (files == null || files.Length ==0) return null;
  52. else {
  53. char[][] rslt = new char[files.Length][];
  54. for (int i = 0; i < files.Length; i++)
  55. rslt[i] = mkArr(System.IO.Path.GetFileName(files[i]));
  56. return rslt;
  57. }
  58. }
  59. } // end of class GPFiles
  60. /* ------------------------------------------------------------ */
  61. public abstract class FILE {
  62. public System.String path;
  63. } // end of class GPFiles.FILE
  64. /* ------------------------------------------------------------ */
  65. } // end of NameSpace GPFiles
  66. /* ------------------------------------------------------------ */