Get DirectoryInfo from FileInfo: name, parent directory name, directory exists : Directory « File Directory Stream « C# / CSharp Tutorial

C# / CSharp Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statement
5. String
6. struct
7. Class
8. Operator Overload
9. delegate
10. Attribute
11. Data Structure
12. Assembly
13. Date Time
14. Development
15. File Directory Stream
16. Preprocessing Directives
17. Regular Expression
18. Generic
19. Reflection
20. Thread
21. I18N Internationalization
22. GUI Windows Forms
23. 2D
24. Design Patterns
25. Windows
26. XML
27. ADO.Net
28. Network
29. Directory Services
30. Security
31. unsafe
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
C# / CSharp Tutorial » File Directory Stream » Directory 
15. 15. 15. Get DirectoryInfo from FileInfo: name, parent directory name, directory exists
using System;
using System.IO;

class MainClass
{
    public static void Main(string[] args)
    {
        FileInfo file = new FileInfo("c:\\test.txt");

        // Display directory information.
        DirectoryInfo dir = file.Directory;

        Console.WriteLine("Checking directory: " + dir.Name);
        Console.WriteLine("In directory: " + dir.Parent.Name);
        Console.Write("Directory exists: ");
        Console.WriteLine(dir.Exists.ToString());

    }
}
Checking directory: c:\

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an ob
ject.
   at MainClass.Main(String[] args)
15. 15. Directory
15. 15. 1. Get the files from the root directory
15. 15. 2. Use file filer on a directory
15. 15. 3. Directory.Exists
15. 15. 4. Get Current Directory
15. 15. 5. Get relative path
15. 15. 6. Changing current directory to c:\\
15. 15. 7. Delete Directory
15. 15. 8. Directory Attributes
15. 15. 9. Use DirectoryInfo to create sub directory
15. 15. 10. List directory under a directory
15. 15. 11. List files under a directory
15. 15. 12. All Directories traverses all sub-directories under the root
15. 15. 13. Traverse all files under the root
15. 15. 14. Recursive Directory use
15. 15. 15. Get DirectoryInfo from FileInfo: name, parent directory name, directory exists
15. 15. 16. DirectoryInfo: creation time, last write time, last access time
15. 15. 17. DirectoryInfo: Directory attribute list and Directory contains
w__w___w___.__j___av_a2__s__.___c_o__m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.