Skip to Main Content
C# Cookbook, 2nd Edition
book

C# Cookbook, 2nd Edition

by Jay Hilyard, Stephen Teilhet
January 2006
Intermediate to advanced content levelIntermediate to advanced
1184 pages
43h 23m
English
O'Reilly Media, Inc.
Content preview from C# Cookbook, 2nd Edition
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
704
|
Chapter 12: Filesystem I/O
To delete a directory, you must first determine whether it exists. If it does not exist,
the delete operation will fail and throw an exception.
See Also
See the “Directory Class” and “DirectoryInfo Class” topics in the MSDN documenta-
tion.
12.11 Manipulating Directory Attributes
Problem
You need to display or manipulate a directory’s attributes or timestamps.
Solution
To display a directory’s timestamps, you can use either the set of static methods from
the
Directory object or the set of instance properties from the DirectoryInfo object.
The static methods are
GetCreationTime, GetLastAccessTime,orGetLastWriteTime.
For example:
public static void DisplayDirAttr(string path)
{
Console.WriteLine(Directory.GetCreationTime(path));
Console.WriteLine(Directory.GetLastAccessTime(path));
Console.WriteLine(Directory.GetLastWriteTime(path));
}
In each case, path is the path to the directory with a timestamp you wish to retrieve,
and the method returns a
DateTime value containing the relevant timestamp. The
instance properties are
CreationTime, LastAccessTime, or LastWriteTime. For example:
public static void DisplayDirAttr(string path)
{
DirectoryInfo dirInfo = Directory.CreateDirectory(path);
Console.WriteLine(dirInfo.CreationTime);
Console.WriteLine(dirInfo.LastAccessTime); ...
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# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard
C# Cookbook

C# Cookbook

Joe Mayo
Head First C#, 4th Edition

Head First C#, 4th Edition

Andrew Stellman, Jennifer Greene

Publisher Resources

ISBN: 0596100639Supplemental ContentCatalog PageErrata