(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / corlib / System.IO / DirectoryInfo.cs
blobbb83fcaa4069435903b5d6b866026347b914ac59
1 //
2 // System.IO.DirectoryInfo.cs
3 //
4 // Author:
5 // Miguel de Icaza, miguel@ximian.com
6 // Jim Richardson, develop@wtfo-guru.com
7 // Dan Lewis, dihlewis@yahoo.co.uk
8 //
9 // Copyright (C) 2002 Ximian, Inc.
10 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
11 //
14 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
23 //
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
26 //
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System;
37 using System.Collections;
39 namespace System.IO {
41 [Serializable]
42 public sealed class DirectoryInfo : FileSystemInfo {
44 public DirectoryInfo (string path) {
45 CheckPath (path);
47 OriginalPath = path;
48 FullPath = Path.GetFullPath (path);
51 // properties
53 public override bool Exists {
54 get {
55 Refresh (false);
57 if (stat.Attributes == MonoIO.InvalidFileAttributes)
58 return false;
60 if ((stat.Attributes & FileAttributes.Directory) == 0)
61 return false;
63 return true;
67 public override string Name {
68 get {
69 string result = Path.GetFileName (FullPath);
70 if (result == null || result == "")
71 return FullPath;
72 return result;
76 public DirectoryInfo Parent {
77 get {
78 string dirname = Path.GetDirectoryName (FullPath);
79 if (dirname == null)
80 return null;
82 return new DirectoryInfo (dirname);
86 public DirectoryInfo Root {
87 get {
88 string root = Path.GetPathRoot (FullPath);
89 if (root == null)
90 return null;
92 return new DirectoryInfo (root);
96 // creational methods
98 public void Create () {
99 Directory.CreateDirectory (FullPath);
102 public DirectoryInfo CreateSubdirectory (string name) {
103 string path = Path.Combine (FullPath, name);
104 Directory.CreateDirectory (path);
106 return new DirectoryInfo (path);
109 // directory listing methods
111 public FileInfo [] GetFiles () {
112 return GetFiles ("*");
115 public FileInfo [] GetFiles (string pattern) {
116 string [] names = Directory.GetFiles (FullPath, pattern);
118 ArrayList infos = new ArrayList ();
119 foreach (string name in names)
120 infos.Add (new FileInfo (name));
122 return (FileInfo []) infos.ToArray (typeof (FileInfo));
125 public DirectoryInfo [] GetDirectories () {
126 return GetDirectories ("*");
129 public DirectoryInfo [] GetDirectories (string pattern) {
130 string [] names = Directory.GetDirectories (FullPath, pattern);
132 ArrayList infos = new ArrayList ();
133 foreach (string name in names)
134 infos.Add (new DirectoryInfo (name));
136 return (DirectoryInfo []) infos.ToArray (typeof (DirectoryInfo));
139 public FileSystemInfo [] GetFileSystemInfos () {
140 return GetFileSystemInfos ("*");
143 public FileSystemInfo [] GetFileSystemInfos (string pattern) {
144 ArrayList infos = new ArrayList ();
145 infos.AddRange (GetDirectories (pattern));
146 infos.AddRange (GetFiles (pattern));
148 return (FileSystemInfo []) infos.ToArray (typeof (FileSystemInfo));
151 // directory management methods
153 public override void Delete () {
154 Delete (false);
157 public void Delete (bool recurse) {
158 Directory.Delete (FullPath, recurse);
161 public void MoveTo (string dest) {
162 Directory.Move (FullPath, Path.GetFullPath (dest));
165 public override string ToString () {
166 return OriginalPath;