2
0

File.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //------------------------------------------------------------------------------
  2. //
  3. // System.IO.File.cs
  4. //
  5. // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
  6. //
  7. // Author: Jim Richardson, [email protected]
  8. // Created: Monday, August 22, 2001
  9. //
  10. // TODO: Research exceptions for all methods
  11. //------------------------------------------------------------------------------
  12. using System;
  13. namespace System.IO
  14. {
  15. /// <summary>
  16. ///
  17. /// </summary>
  18. public sealed class File : Object
  19. {
  20. /// <summary>
  21. /// Creates a StreamWriter that appends text to a file creating the file if needed
  22. /// </summary>
  23. public static StreamWriter AppendText(string path)
  24. { // TODO: Implement
  25. return null;
  26. }
  27. /// <summary>
  28. /// Copies a file overwriting existing if necessary
  29. /// </summary>
  30. public static void Copy(string sourceFilename, string destFilename)
  31. {
  32. Copy(sourceFilename, destFilename, true);
  33. }
  34. /// <summary>
  35. /// Copies a file overwriting existing if specified
  36. /// </summary>
  37. public static void Copy(string sourceFilename, string destFilename, bool bOverwrite)
  38. { // TODO: Implement
  39. }
  40. /// <summary>
  41. /// Creates a file given the fully qualified path
  42. /// </summary>
  43. public static FileStream Create(string path)
  44. { // TODO: Research default buffersize
  45. return Create(path, 1024);
  46. }
  47. /// <summary>
  48. /// Creates a file given the fully qualified path using specified buffersize
  49. /// </summary>
  50. public static FileStream Create(string path, int buffersize)
  51. { // TODO: Implement
  52. return null;
  53. }
  54. /// <summary>
  55. /// Delete a file
  56. /// </summary>
  57. public static void Delete(string path)
  58. { // TODO: Implement
  59. }
  60. /// <summary>
  61. /// Returns true if file exists on disk
  62. /// </summary>
  63. public static bool Exists(string path)
  64. { // TODO: Implement
  65. return false;
  66. }
  67. /// <summary>
  68. /// Returns the date and time the file specified by path was created
  69. /// </summary>
  70. public static FileAttributes GetAttributes(string path)
  71. {
  72. FileInfo fInfo = new FileInfo(path);
  73. return fInfo.Attributes;
  74. }
  75. /// <summary>
  76. /// Returns the date and time the directory specified by path was created
  77. /// </summary>
  78. public static DateTime GetCreationTime(string path)
  79. {
  80. return getInfo(path).CreationTime;
  81. }
  82. /// <summary>
  83. /// Returns the date and time the directory specified by path was last accessed
  84. /// </summary>
  85. public static DateTime GetLastAccessTime(string path)
  86. {
  87. return getInfo(path).LastAccessTime;
  88. }
  89. /// <summary>
  90. /// Returns the date and time the directory specified by path was last modified
  91. /// </summary>
  92. public static DateTime GetLastWriteTime(string path)
  93. {
  94. return getInfo(path).LastWriteTime;
  95. }
  96. /// <summary>
  97. /// Moves a file
  98. /// </summary>
  99. public static void Move(string srcFilename, string destFilename)
  100. {
  101. getInfo(srcFilename).MoveTo(destFilename);
  102. }
  103. /// <summary>
  104. /// Open a file for exclusive reading and writing
  105. /// </summary>
  106. public static FileStream Open(string path, FileMode mode)
  107. { // TODO: research if exclusive is the correct default
  108. return getInfo(path).Open(mode, FileAccess.ReadWrite);
  109. }
  110. /// <summary>
  111. /// Open a file for exclusive access specified by mode
  112. /// </summary>
  113. public static FileStream Open(string path, FileMode mode, FileAccess access)
  114. { // TODO: research if exclusive is the correct default
  115. return getInfo(path).Open(mode, access, FileShare.None);
  116. }
  117. /// <summary>
  118. /// Open a file access specified by mode, sharing specified by share
  119. /// </summary>
  120. public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share)
  121. {
  122. return getInfo(path).Open(mode, access, share);
  123. }
  124. /// <summary>
  125. /// Open a FileStream for reading and writing
  126. /// </summary>
  127. public static FileStream OpenRead(string path)
  128. { // TODO: find out what default share should be
  129. return getInfo(path).OpenRead();
  130. }
  131. /// <summary>
  132. /// Open a StreamReader
  133. /// </summary>
  134. public static StreamReader OpenText(string path)
  135. {
  136. return getInfo(path).OpenText();
  137. }
  138. /// <summary>
  139. /// Open a FileStream for reading and writing
  140. /// </summary>
  141. public FileStream OpenWrite(string path)
  142. {
  143. return getInfo(path).OpenWrite();
  144. }
  145. /// <summary>
  146. /// Sets the attributes of file specified by path
  147. /// </summary>
  148. public static void SetAttributes(string path, FileAttributes attributes)
  149. {
  150. getInfo(path).Attributes = attributes;
  151. }
  152. /// <summary>
  153. /// Sets the creation time of the directory specified by path
  154. /// </summary>
  155. public static void SetCreationTime(string path, DateTime creationTime)
  156. {
  157. getInfo(path).CreationTime = creationTime;
  158. }
  159. /// <summary>
  160. /// Sets the last access time of the directory specified by path
  161. /// </summary>
  162. public static void SetLastAccessTime(string path, DateTime accessTime)
  163. {
  164. getInfo(path).LastAccessTime = accessTime;
  165. }
  166. /// <summary>
  167. /// Sets the last write time of the directory specified by path
  168. /// </summary>
  169. public static void SetLastWriteTime(string path, DateTime modifiedTime)
  170. {
  171. getInfo(path).LastWriteTime = modifiedTime;
  172. }
  173. private static FileInfo getInfo(string path)
  174. {
  175. return new FileInfo(path);
  176. }
  177. }
  178. }