GPFiles.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. public static char pathSep = ';';
  11. public static char fileSep = '\\';
  12. public static char optChar = '/';
  13. /* ---------------------------------- */
  14. private static System.String mkStr(char[] arr) {
  15. int ix = 0;
  16. char ch;
  17. do {
  18. ch = arr[ix]; ix++;
  19. } while (ch != '\0');
  20. return new System.String(arr,0,ix-1);
  21. }
  22. private static char[] mkArr(System.String str) {
  23. char[] rslt = new char[str.Length + 1];
  24. str.CopyTo(0, rslt, 0, str.Length);
  25. rslt[str.Length] = '\0';
  26. return rslt;
  27. }
  28. /* ---------------------------------- */
  29. public static bool isOlder(FILE first, FILE second) {
  30. int comp = System.DateTime.Compare(
  31. System.IO.File.GetLastWriteTime(first.path),
  32. System.IO.File.GetLastWriteTime(second.path)
  33. );
  34. return comp == -1;
  35. }
  36. public static void MakeDirectory(char[] dirName) {
  37. System.String path = mkStr(dirName);
  38. System.IO.Directory.CreateDirectory(path);
  39. }
  40. public static char[] CurrentDirectory() {
  41. return mkArr(System.IO.Directory.GetCurrentDirectory());
  42. }
  43. public static bool exists(char[] filName) {
  44. System.String path = mkStr(filName);
  45. return System.IO.File.Exists(path);
  46. }
  47. public static char[][] FileList(char[] dirPath) {
  48. string dirStr = mkStr(dirPath);
  49. string[] files = System.IO.Directory.GetFiles(dirStr);
  50. if (files == null || files.Length ==0) return null;
  51. else {
  52. char[][] rslt = new char[files.Length][];
  53. for (int i = 0; i < files.Length; i++)
  54. rslt[i] = mkArr(System.IO.Path.GetFileName(files[i]));
  55. return rslt;
  56. }
  57. }
  58. } // end of class GPFiles
  59. /* ------------------------------------------------------------ */
  60. public abstract class FILE {
  61. public System.String path;
  62. } // end of class GPFiles.FILE
  63. /* ------------------------------------------------------------ */
  64. } // end of NameSpace GPFiles
  65. /* ------------------------------------------------------------ */