2 // System.IO.DirectoryInfo.cs
\r
5 // Miguel de Icaza, miguel@ximian.com
\r
6 // Jim Richardson, develop@wtfo-guru.com
\r
7 // Dan Lewis, dihlewis@yahoo.co.uk
\r
9 // Copyright (C) 2002 Ximian, Inc.
\r
10 // Copyright (C) 2001 Moonlight Enterprises, All Rights Reserved
\r
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;
\r
39 namespace System.IO {
\r
42 public sealed class DirectoryInfo : FileSystemInfo {
\r
44 public DirectoryInfo (string path) {
\r
47 OriginalPath = path;
\r
48 FullPath = Path.GetFullPath (path);
\r
53 public override bool Exists {
\r
57 if (stat.Attributes == MonoIO.InvalidFileAttributes)
\r
60 if ((stat.Attributes & FileAttributes.Directory) == 0)
\r
67 public override string Name {
\r
69 string result = Path.GetFileName (FullPath);
\r
70 if (result == null || result == "")
\r
76 public DirectoryInfo Parent {
\r
78 string dirname = Path.GetDirectoryName (FullPath);
\r
79 if (dirname == null)
\r
82 return new DirectoryInfo (dirname);
\r
86 public DirectoryInfo Root {
\r
88 string root = Path.GetPathRoot (FullPath);
\r
92 return new DirectoryInfo (root);
\r
96 // creational methods
\r
98 public void Create () {
\r
99 Directory.CreateDirectory (FullPath);
\r
102 public DirectoryInfo CreateSubdirectory (string name) {
105 string path = Path.Combine (FullPath, name);
\r
106 Directory.CreateDirectory (path);
\r
108 return new DirectoryInfo (path);
\r
111 // directory listing methods
\r
113 public FileInfo [] GetFiles () {
\r
114 return GetFiles ("*");
\r
117 public FileInfo [] GetFiles (string pattern) {
\r
118 string [] names = Directory.GetFiles (FullPath, pattern);
\r
120 ArrayList infos = new ArrayList ();
\r
121 foreach (string name in names)
\r
122 infos.Add (new FileInfo (name));
\r
124 return (FileInfo []) infos.ToArray (typeof (FileInfo));
\r
127 public DirectoryInfo [] GetDirectories () {
\r
128 return GetDirectories ("*");
\r
131 public DirectoryInfo [] GetDirectories (string pattern) {
\r
132 string [] names = Directory.GetDirectories (FullPath, pattern);
\r
134 ArrayList infos = new ArrayList ();
\r
135 foreach (string name in names)
\r
136 infos.Add (new DirectoryInfo (name));
\r
138 return (DirectoryInfo []) infos.ToArray (typeof (DirectoryInfo));
\r
141 public FileSystemInfo [] GetFileSystemInfos () {
\r
142 return GetFileSystemInfos ("*");
\r
145 public FileSystemInfo [] GetFileSystemInfos (string pattern) {
\r
146 ArrayList infos = new ArrayList ();
\r
147 infos.AddRange (GetDirectories (pattern));
\r
148 infos.AddRange (GetFiles (pattern));
\r
150 return (FileSystemInfo []) infos.ToArray (typeof (FileSystemInfo));
\r
153 // directory management methods
\r
155 public override void Delete () {
\r
159 public void Delete (bool recurse) {
\r
160 Directory.Delete (FullPath, recurse);
\r
163 public void MoveTo (string dest) {
\r
164 Directory.Move (FullPath, Path.GetFullPath (dest));
\r
167 public override string ToString () {
\r
168 return OriginalPath;
\r