Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

Name

DirectoryInfo

Synopsis

This class provides the same functionality as Directory, but in a strongly typed, object-oriented manner. An instance of this type represents a single directory. This class extends FileSystemInfo and implements all its methods. In addition, it adds Parent and Root properties to return the parent and root directories respectively. Similarly, it also supplies GetDirectories() and GetFiles(), to retrieve its subdirectories and files, as well as GetFileSystemInfos(), which returns both the files and subdirectories contained by the current directory. MoveTo() allows you to move a directory from one place to another.

Given the similarity between this type and the Directory type, it may not be clear when one should be used in place of the other. The key difference is the Directory class is a collection of static utility functions, whereas a DirectoryInfo object is an actual object, maintaining state and identity in the classic style of all objects. (In fact, the DirectoryInfo methods often map over to use the corresponding Directory methods.)

public sealed class DirectoryInfo : FileSystemInfo {
// Public Constructors
   public method DirectoryInfo(string path);  
// Public Instance Properties
   public override field bool Exists{get; }                      // overrides FileSystemInfo
   public override field string Name{get; }                      // overrides FileSystemInfo
   public field DirectoryInfo Parent{get; } 
   public field DirectoryInfo Root{get; } 
// Public Instance Methods
   public method void Create(); public ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata