2 // System.IO.DirectoryInfo.cs
5 // Miguel de Icaza, miguel@ximian.com
6 // Jim Richardson, develop@wtfo-guru.com
7 // Dan Lewis, dihlewis@yahoo.co.uk
9 // Copyright (C) 2002 Ximian, Inc.
10 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
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:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
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.
37 using System
.Collections
;
42 public sealed class DirectoryInfo
: FileSystemInfo
{
44 public DirectoryInfo (string path
) {
48 FullPath
= Path
.GetFullPath (path
);
53 public override bool Exists
{
57 if (stat
.Attributes
== MonoIO
.InvalidFileAttributes
)
60 if ((stat
.Attributes
& FileAttributes
.Directory
) == 0)
67 public override string Name
{
69 string result
= Path
.GetFileName (FullPath
);
70 if (result
== null || result
== "")
76 public DirectoryInfo Parent
{
78 string dirname
= Path
.GetDirectoryName (FullPath
);
82 return new DirectoryInfo (dirname
);
86 public DirectoryInfo Root
{
88 string root
= Path
.GetPathRoot (FullPath
);
92 return new DirectoryInfo (root
);
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 () {
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 () {