2 // System.IO.File.cs
\r
6 // Miguel de Icaza (miguel@ximian.com)
\r
7 // Jim Richardson (develop@wtfo-guru.com)
\r
8 // Dan Lewis (dihlewis@yahoo.co.uk)
\r
10 // Copyright 2002 Ximian, Inc. http://www.ximian.com
\r
11 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
\r
21 public sealed class File : Object
\r
25 public static StreamWriter AppendText (string path)
\r
27 return new StreamWriter (path, true);
\r
30 public static void Copy (string sourceFilename, string destFilename)
\r
32 Copy (sourceFilename, destFilename, true);
\r
35 public static void Copy (string src, string dest, bool overwrite)
\r
37 if (src == null || dest == null)
\r
38 throw new ArgumentNullException ();
\r
39 if (src == "" || dest == null ||
\r
40 src.IndexOfAny (Path.InvalidPathChars) != -1 ||
\r
41 dest.IndexOfAny (Path.InvalidPathChars) != -1)
\r
42 throw new ArgumentException ();
\r
44 if (!MonoIO.CopyFile (src, dest, overwrite))
\r
45 throw MonoIO.GetException ();
\r
48 public static FileStream Create (string path)
\r
50 return Create (path, 8192);
\r
53 public static FileStream Create (string path, int buffersize)
\r
55 return new FileStream (path, FileMode.Create, FileAccess.ReadWrite,
\r
56 FileShare.None, buffersize);
\r
59 public static void Delete (string path)
\r
62 throw new ArgumentNullException ();
\r
63 if (path == "" || path.IndexOfAny (Path.InvalidPathChars) != -1)
\r
64 throw new ArgumentException ();
\r
66 if (!MonoIO.DeleteFile (path))
\r
67 throw MonoIO.GetException ();
\r
70 public static bool Exists (string path)
\r
72 return MonoIO.ExistsFile (path);
\r
75 public static FileAttributes GetAttributes (string path)
\r
77 return MonoIO.GetFileAttributes (path);
\r
80 public static DateTime GetCreationTime (string path)
\r
84 MonoIO.GetFileStat (path, out stat);
\r
85 return DateTime.FromFileTime (stat.CreationTime);
\r
88 public static DateTime GetLastAccessTime (string path)
\r
92 MonoIO.GetFileStat (path, out stat);
\r
93 return DateTime.FromFileTime (stat.LastAccessTime);
\r
96 public static DateTime GetLastWriteTime (string path)
\r
100 MonoIO.GetFileStat (path, out stat);
\r
101 return DateTime.FromFileTime (stat.LastWriteTime);
\r
104 public static void Move (string src, string dest)
\r
106 if (src == null || dest == null)
\r
107 throw new ArgumentNullException ();
\r
108 if (src == "" || dest == null ||
\r
109 src.IndexOfAny (Path.InvalidPathChars) != -1 ||
\r
110 dest.IndexOfAny (Path.InvalidPathChars) != -1)
\r
111 throw new ArgumentException ();
\r
113 if (!MonoIO.MoveFile (src, dest))
\r
114 throw MonoIO.GetException ();
\r
117 public static FileStream Open (string path, FileMode mode)
\r
119 return new FileStream (path, mode, FileAccess.ReadWrite, FileShare.None);
\r
122 public static FileStream Open (string path, FileMode mode, FileAccess access)
\r
124 return new FileStream (path, mode, access, FileShare.None);
\r
127 public static FileStream Open (string path, FileMode mode, FileAccess access,
\r
130 return new FileStream (path, mode, access, share);
\r
133 public static FileStream OpenRead (string path)
\r
135 return new FileStream (path, FileMode.Open, FileAccess.Read, FileShare.Read);
\r
138 public static StreamReader OpenText (string path)
\r
140 return new StreamReader (path);
\r
143 public static FileStream OpenWrite (string path)
\r
145 return new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
\r
148 public static void SetAttributes (string path, FileAttributes attributes)
\r
150 if (!MonoIO.SetFileAttributes (path, attributes))
\r
151 throw MonoIO.GetException (path);
\r
154 public static void SetCreationTime (string path, DateTime creation_time)
\r
156 if (!MonoIO.SetFileTime (path, creation_time.Ticks, -1, -1))
\r
157 throw MonoIO.GetException (path);
\r
160 public static void SetLastAccessTime (string path, DateTime last_access_time)
\r
162 if (!MonoIO.SetFileTime (path, -1, last_access_time.Ticks, -1))
\r
163 throw MonoIO.GetException (path);
\r
166 public static void SetLastWriteTime (string path, DateTime last_write_time)
\r
168 if (!MonoIO.SetFileTime (path, -1, -1, last_write_time.Ticks))
\r
169 throw MonoIO.GetException (path);
\r