Manipulate a Directory

Problem

You want to delete, rename, or check if a directory exists. Or, you want to retrieve information about a directory such as its attributes or creation date.

Solution

Create a DirectoryInfo instance for the directory, and use its properties and methods.

Discussion

The DirectoryInfo object works almost the same as the FileInfo object. You can use the same properties for retrieving attributes, names, and file system timestamps. You can also use the same methods for moving, deleting, and renaming directories as you would with files. These members are described in Table 5-1. In addition, the DirectoryInfo object provides some directory-specific members, which are shown in Table 5-3.

Table 5-3. DirectoryInfo Members

Member

Description ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.