<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FFile_Directory_Stream%2FDirectory</id>
		<title>Csharp/CSharp Tutorial/File Directory Stream/Directory - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://nfex.ru/index.php?action=history&amp;feed=atom&amp;title=Csharp%2FCSharp_Tutorial%2FFile_Directory_Stream%2FDirectory"/>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/Directory&amp;action=history"/>
		<updated>2026-04-29T16:35:05Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/Directory&amp;diff=6832&amp;oldid=prev</id>
		<title> в 15:31, 26 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/Directory&amp;diff=6832&amp;oldid=prev"/>
				<updated>2010-05-26T15:31:53Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 15:31, 26 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/Directory&amp;diff=6833&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://nfex.ru/index.php?title=Csharp/CSharp_Tutorial/File_Directory_Stream/Directory&amp;diff=6833&amp;oldid=prev"/>
				<updated>2010-05-26T12:20:32Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==All Directories traverses all sub-directories under the root==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Collections.Specialized;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.IO.rupression;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Net.Mail;&lt;br /&gt;
using System.Net.Sockets;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        DirectoryInfo root = new DirectoryInfo(@&amp;quot;C:\Program Files\&amp;quot;);&lt;br /&gt;
        DirectoryInfo[] dirs = root.GetDirectories(&amp;quot;*&amp;quot;, SearchOption.TopDirectoryOnly);&lt;br /&gt;
        Console.WriteLine(&amp;quot;{0} subdirectories:&amp;quot;, root.FullName);&lt;br /&gt;
        foreach (DirectoryInfo subDir in dirs)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;    {0}&amp;quot;, subDir.Name);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;C:\Program Files\ subdirectories:&lt;br /&gt;
    Adobe&lt;br /&gt;
    AMD&lt;br /&gt;
    ATI Technologies&lt;br /&gt;
    Common Files&lt;br /&gt;
    ComPlus Applications&lt;br /&gt;
    CONEXANT&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Changing current directory to c:\\==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
static class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
       Directory.SetCurrentDirectory(@&amp;quot;c:\&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Create directory structure==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO.IsolatedStorage;&lt;br /&gt;
using System.IO;&lt;br /&gt;
  class MainClass&lt;br /&gt;
  {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly())&lt;br /&gt;
      {&lt;br /&gt;
        store.CreateDirectory(@&amp;quot;MyDir\XmlData&amp;quot;);&lt;br /&gt;
        store.CreateDirectory(&amp;quot;MyDir\\BinaryData&amp;quot;);&lt;br /&gt;
        store.CreateDirectory(&amp;quot;MyDir/TextData&amp;quot;);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Creating Subdirectory and Manipulating File==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Text;&lt;br /&gt;
    class Tester&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            ExploreDirectory(new DirectoryInfo(&amp;quot;c:\\&amp;quot;));&lt;br /&gt;
        }&lt;br /&gt;
        private static void ExploreDirectory(DirectoryInfo dir)&lt;br /&gt;
        {&lt;br /&gt;
            string newDirectory = &amp;quot;newTest&amp;quot;;&lt;br /&gt;
            DirectoryInfo newSubDir = dir.CreateSubdirectory(newDirectory);&lt;br /&gt;
            FileInfo[] filesInDir = dir.GetFiles();&lt;br /&gt;
            foreach (FileInfo file in filesInDir)&lt;br /&gt;
            {&lt;br /&gt;
                string fullName = newSubDir.FullName +&amp;quot;\\&amp;quot; + file.Name;&lt;br /&gt;
                file.CopyTo(fullName);&lt;br /&gt;
                Console.WriteLine(file.FullName);&lt;br /&gt;
            }&lt;br /&gt;
            filesInDir = newSubDir.GetFiles();&lt;br /&gt;
            int counter = 0;&lt;br /&gt;
            foreach (FileInfo file in filesInDir)&lt;br /&gt;
            {&lt;br /&gt;
                string fullName = file.FullName;&lt;br /&gt;
                file.MoveTo(fullName + &amp;quot;.bak&amp;quot;);&lt;br /&gt;
                Console.WriteLine(&amp;quot;{0} renamed to {1}&amp;quot;,fullName, file.FullName);&lt;br /&gt;
            }&lt;br /&gt;
            newSubDir.Delete(true); &lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Delete Directory==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MaionClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main(String[] args)&lt;br /&gt;
  {&lt;br /&gt;
    try&lt;br /&gt;
    {&lt;br /&gt;
      Directory.Delete(@&amp;quot;C:\WinNT\MyFoo&amp;quot;);&lt;br /&gt;
      Directory.Delete(@&amp;quot;C:\WinNT\MyBar&amp;quot;, true);&lt;br /&gt;
    }&lt;br /&gt;
    catch(IOException e)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(e.Message);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Directory Attributes==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void DecipherAttributes(FileAttributes f) &lt;br /&gt;
  {&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.Archive) == FileAttributes.Archive)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Archive&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.rupressed) == FileAttributes.rupressed)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Compressed&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.Device) == FileAttributes.Device)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Device&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.Directory)   == FileAttributes.Directory)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Directory&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.Encrypted)  == FileAttributes.Encrypted)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Encrypted&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.Hidden)  == FileAttributes.Hidden)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Hidden&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.NotContentIndexed)  == FileAttributes.NotContentIndexed)&lt;br /&gt;
      Console.WriteLine(&amp;quot;NotContentIndexed&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.Offline)  == FileAttributes.Offline)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Offline&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.ReadOnly)  == FileAttributes.ReadOnly)&lt;br /&gt;
      Console.WriteLine(&amp;quot;ReadOnly&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.ReparsePoint)  == FileAttributes.ReparsePoint)&lt;br /&gt;
      Console.WriteLine(&amp;quot;ReparsePoint&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.SparseFile)  == FileAttributes.SparseFile)&lt;br /&gt;
      Console.WriteLine(&amp;quot;SparseFile&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.System)  == FileAttributes.System)&lt;br /&gt;
      Console.WriteLine(&amp;quot;System&amp;quot;);&lt;br /&gt;
    if ((f &amp;amp; FileAttributes.Temporary)  == FileAttributes.Temporary)&lt;br /&gt;
      Console.WriteLine(&amp;quot;Temporary&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    DirectoryInfo di = new DirectoryInfo(&amp;quot;c:\\&amp;quot;);&lt;br /&gt;
    &lt;br /&gt;
    FileAttributes f = di.Attributes;&lt;br /&gt;
    Console.WriteLine(&amp;quot;Directory c:\\ has attributes:&amp;quot;);&lt;br /&gt;
    DecipherAttributes(f);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Directory c:\ has attributes:&lt;br /&gt;
Directory&lt;br /&gt;
Hidden&lt;br /&gt;
System&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Directory.Exists==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
static class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        Console.WriteLine(Directory.Exists(&amp;quot;c:\\&amp;quot;));&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;True&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==DirectoryInfo: creation time, last write time, last access time==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        FileInfo file = new FileInfo(&amp;quot;c:\\test.txt&amp;quot;);    &lt;br /&gt;
        // Display directory information.&lt;br /&gt;
        DirectoryInfo dir = file.Directory;&lt;br /&gt;
        if (dir.Exists)&lt;br /&gt;
        {&lt;br /&gt;
            Console.Write(&amp;quot;Directory created: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(dir.CreationTime.ToString());&lt;br /&gt;
            Console.Write(&amp;quot;Directory last updated: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(dir.LastWriteTime.ToString());&lt;br /&gt;
            Console.Write(&amp;quot;Directory last accessed: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(dir.LastAccessTime.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    &lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Directory created: 27/08/2006 3:07:02 PM&lt;br /&gt;
Directory last updated: 25/03/2007 2:04:08 PM&lt;br /&gt;
Directory last accessed: 25/03/2007 2:11:11 PM&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==DirectoryInfo: Directory attribute list and Directory contains==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        FileInfo file = new FileInfo(&amp;quot;c:\\test.txt&amp;quot;);&lt;br /&gt;
        // Display directory information.&lt;br /&gt;
        DirectoryInfo dir = file.Directory;&lt;br /&gt;
        if (dir.Exists)&lt;br /&gt;
        {&lt;br /&gt;
            Console.Write(&amp;quot;Directory attribute list: &amp;quot;);&lt;br /&gt;
            Console.WriteLine(dir.Attributes.ToString());&lt;br /&gt;
            Console.WriteLine(&amp;quot;Directory contains: &amp;quot; + dir.GetFiles().Length.ToString() + &amp;quot; files&amp;quot;);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Directory attribute list: Hidden, System, Directory&lt;br /&gt;
Directory contains: 12 files&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Exploring Files And Sub directories==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Text;&lt;br /&gt;
   class Tester&lt;br /&gt;
   {&lt;br /&gt;
      static int dirCounter = 1;&lt;br /&gt;
      static int fileCounter = 0;&lt;br /&gt;
      public static void Main()&lt;br /&gt;
      {&lt;br /&gt;
         ExploreDirectory( new DirectoryInfo( &amp;quot;c:\\&amp;quot;) );&lt;br /&gt;
      }&lt;br /&gt;
      static void ExploreDirectory( DirectoryInfo dir )&lt;br /&gt;
      {&lt;br /&gt;
         FileInfo[] filesInDir = dir.GetFiles();&lt;br /&gt;
         foreach ( FileInfo file in filesInDir )&lt;br /&gt;
         {&lt;br /&gt;
            Console.WriteLine( &amp;quot;{0} [{1}] Size: {2} bytes&amp;quot;,&lt;br /&gt;
               file.Name,&lt;br /&gt;
               file.LastWriteTime,&lt;br /&gt;
               file.Length );&lt;br /&gt;
            fileCounter++;&lt;br /&gt;
         }&lt;br /&gt;
         DirectoryInfo[] directories = dir.GetDirectories();&lt;br /&gt;
         foreach ( DirectoryInfo newDir in directories )&lt;br /&gt;
         {&lt;br /&gt;
            dirCounter++;  // increment the counter&lt;br /&gt;
            ExploreDirectory( newDir );&lt;br /&gt;
         }&lt;br /&gt;
      }&lt;br /&gt;
   }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get Current Directory==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
static class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Console.WriteLine(&amp;quot;Using: &amp;quot; + Directory.GetCurrentDirectory());&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Using: C:\Java_Dev\WEB\dev\CSharp&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get DirectoryInfo from FileInfo: name, parent directory name, directory exists==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        FileInfo file = new FileInfo(&amp;quot;c:\\test.txt&amp;quot;);&lt;br /&gt;
        // Display directory information.&lt;br /&gt;
        DirectoryInfo dir = file.Directory;&lt;br /&gt;
        Console.WriteLine(&amp;quot;Checking directory: &amp;quot; + dir.Name);&lt;br /&gt;
        Console.WriteLine(&amp;quot;In directory: &amp;quot; + dir.Parent.Name);&lt;br /&gt;
        Console.Write(&amp;quot;Directory exists: &amp;quot;);&lt;br /&gt;
        Console.WriteLine(dir.Exists.ToString());&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Checking directory: c:\&lt;br /&gt;
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an ob&lt;br /&gt;
ject.&lt;br /&gt;
   at MainClass.Main(String[] args)&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get relative path==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
static class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        Console.WriteLine(&amp;quot;The relative path &amp;quot;file.txt&amp;quot; &amp;quot; + Path.GetFullPath(&amp;quot;file.txt&amp;quot;));&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;c:\file.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Get the files from the root directory==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    string[] aFiles = Directory.GetFiles(&amp;quot;c:\\&amp;quot;);&lt;br /&gt;
    foreach (string s in aFiles)&lt;br /&gt;
      Console.WriteLine(s);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;c:\AUTOEXEC.BAT&lt;br /&gt;
c:\boot.ini&lt;br /&gt;
c:\CONFIG.SYS&lt;br /&gt;
c:\hiberfil.sys&lt;br /&gt;
c:\initest.ini&lt;br /&gt;
c:\IO.SYS&lt;br /&gt;
c:\MSDOS.SYS&lt;br /&gt;
c:\myfile.txt&lt;br /&gt;
c:\NTDETECT.ru&lt;br /&gt;
c:\ntldr&lt;br /&gt;
c:\pagefile.sys&lt;br /&gt;
c:\records.bin&lt;br /&gt;
c:\Test.txt&lt;br /&gt;
c:\test.xml&lt;br /&gt;
c:\Testing.txt&lt;br /&gt;
c:\xmlWriterTest.xml&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==List directory under a directory==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
  static void Main(string[] args)&lt;br /&gt;
  {&lt;br /&gt;
    DirectoryInfo MyRoot = new DirectoryInfo(@&amp;quot;c:\projects&amp;quot;);&lt;br /&gt;
    DirectoryInfo[] MySub = MyRoot.GetDirectories();&lt;br /&gt;
    foreach (DirectoryInfo D in MySub)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(D.Name);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==List files under a directory==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
  static void Main(string[] args)&lt;br /&gt;
  {&lt;br /&gt;
    DirectoryInfo MyRoot = new DirectoryInfo(@&amp;quot;c:\projects&amp;quot;);&lt;br /&gt;
    FileInfo[] MyFiles = MyRoot.GetFiles();&lt;br /&gt;
    foreach (FileInfo F in MyFiles)&lt;br /&gt;
    {&lt;br /&gt;
      Console.WriteLine(F.Name);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Testing.txt&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Modify directory structure==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
&lt;br /&gt;
  class Program&lt;br /&gt;
  {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      DirectoryInfo dir = new DirectoryInfo(&amp;quot;.&amp;quot;);&lt;br /&gt;
      // Create \MyFolder off initial directory.&lt;br /&gt;
      dir.CreateSubdirectory(&amp;quot;MyFolder&amp;quot;);&lt;br /&gt;
      // Capture returned DirectoryInfo object.&lt;br /&gt;
      DirectoryInfo myDataFolder = dir.CreateSubdirectory(@&amp;quot;MyFolder2\Data&amp;quot;);&lt;br /&gt;
      // Prints path to ..\MyFolder2\Data.&lt;br /&gt;
      Console.WriteLine(&amp;quot;New Folder is: {0}&amp;quot;, myDataFolder);&lt;br /&gt;
    }&lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Recursely Explore Directories==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Text;&lt;br /&gt;
    class Tester&lt;br /&gt;
    {&lt;br /&gt;
        public static void Main()&lt;br /&gt;
        {&lt;br /&gt;
            ExploreDirectory(new DirectoryInfo(&amp;quot;c:\\&amp;quot;));&lt;br /&gt;
        }&lt;br /&gt;
        private static void ExploreDirectory(DirectoryInfo dir)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;[{0}] {1} \n&amp;quot;,dir.Name, dir.LastAccessTime);&lt;br /&gt;
            DirectoryInfo[] directories = dir.GetDirectories();&lt;br /&gt;
            foreach (DirectoryInfo newDir in directories)&lt;br /&gt;
            {&lt;br /&gt;
                ExploreDirectory(newDir);&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Recursive Directory use==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
class MainClass&lt;br /&gt;
{&lt;br /&gt;
  public static void ShowDirectory(DirectoryInfo di, int intLevel) &lt;br /&gt;
  {&lt;br /&gt;
    string strPad = new String(&amp;quot; &amp;quot;, 2*intLevel);&lt;br /&gt;
    Console.WriteLine(strPad + di.Name);&lt;br /&gt;
    foreach (DirectoryInfo diChild in di.GetDirectories())&lt;br /&gt;
      ShowDirectory(diChild, intLevel+1);&lt;br /&gt;
  }&lt;br /&gt;
  public static void Main() &lt;br /&gt;
  {&lt;br /&gt;
    DirectoryInfo di = new DirectoryInfo(&amp;quot;c:\\&amp;quot;);&lt;br /&gt;
    ShowDirectory(di, 0);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;c:\&lt;br /&gt;
  b&lt;br /&gt;
  Documents and Settings&lt;br /&gt;
    All Users&lt;br /&gt;
      Application Data&lt;br /&gt;
        Adobe&lt;br /&gt;
          Acrobat&lt;br /&gt;
            6.0&lt;br /&gt;
              Replicate&lt;br /&gt;
                Security&lt;br /&gt;
        Microsoft&lt;br /&gt;
          CoreCon&lt;br /&gt;
^CTerminate batch job (Y/N)? n&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Show basic directory info==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
&lt;br /&gt;
  class Program&lt;br /&gt;
  {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      DirectoryInfo dir = new DirectoryInfo(@&amp;quot;C:\Windows&amp;quot;);&lt;br /&gt;
      // Dump directory information.&lt;br /&gt;
      Console.WriteLine(&amp;quot;***** Directory Info *****&amp;quot;);&lt;br /&gt;
      Console.WriteLine(&amp;quot;FullName: {0}&amp;quot;, dir.FullName);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Name: {0}&amp;quot;, dir.Name);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Parent: {0}&amp;quot;, dir.Parent);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Creation: {0}&amp;quot;, dir.CreationTime);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Attributes: {0}&amp;quot;, dir.Attributes);&lt;br /&gt;
      Console.WriteLine(&amp;quot;Root: {0}&amp;quot;, dir.Root);&lt;br /&gt;
    }&lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Traverse all files under the root==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Collections.Specialized;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.IO.rupression;&lt;br /&gt;
using System.Net;&lt;br /&gt;
using System.Net.Mail;&lt;br /&gt;
using System.Net.Sockets;&lt;br /&gt;
using System.Runtime.InteropServices;&lt;br /&gt;
using System.Text;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
    public static void Main()&lt;br /&gt;
    {&lt;br /&gt;
        DirectoryInfo root = new DirectoryInfo(@&amp;quot;C:\Program Files\&amp;quot;);&lt;br /&gt;
        DirectoryInfo[] dirs = root.GetDirectories(&amp;quot;*&amp;quot;, SearchOption.TopDirectoryOnly);&lt;br /&gt;
        Console.WriteLine(&amp;quot;{0} subdirectories:&amp;quot;, root.FullName);&lt;br /&gt;
        FileInfo[] files = root.GetFiles();&lt;br /&gt;
        Console.WriteLine(&amp;quot;files:&amp;quot;);&lt;br /&gt;
        foreach (FileInfo file in files)&lt;br /&gt;
        {&lt;br /&gt;
            Console.WriteLine(&amp;quot;    {0} ({1} bytes)&amp;quot;, file.Name, file.Length);&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;C:\Program Files\ subdirectories:&lt;br /&gt;
files:&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use DirectoryInfo to create sub directory==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
public class MainClass&lt;br /&gt;
{&lt;br /&gt;
  static void Main(string[] args)&lt;br /&gt;
  {&lt;br /&gt;
    DirectoryInfo MyRoot = new DirectoryInfo(@&amp;quot;c:\projects&amp;quot;);&lt;br /&gt;
        MyRoot.CreateSubdirectory(&amp;quot;MyFolder&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use file filer on a directory==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.IO;&lt;br /&gt;
static class MainClass&lt;br /&gt;
{&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
        DirectoryInfo dir = new DirectoryInfo(&amp;quot;c:\\a&amp;quot;);&lt;br /&gt;
        FileInfo[] files = dir.GetFiles(&amp;quot;*.gif&amp;quot;);&lt;br /&gt;
        // Display the name of all the files.&lt;br /&gt;
        foreach (FileInfo file in files)&lt;br /&gt;
        {&lt;br /&gt;
            Console.Write(&amp;quot;Name: &amp;quot; + file.Name + &amp;quot;  &amp;quot;);&lt;br /&gt;
            Console.WriteLine(&amp;quot;Size: &amp;quot; + file.Length.ToString());&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using Directory type==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;csharp&amp;quot;&amp;gt;using System;&lt;br /&gt;
using System.Collections.Generic;&lt;br /&gt;
using System.Text;&lt;br /&gt;
using System.IO;&lt;br /&gt;
using System.Linq;&lt;br /&gt;
&lt;br /&gt;
  class Program&lt;br /&gt;
  {&lt;br /&gt;
    static void Main(string[] args)&lt;br /&gt;
    {&lt;br /&gt;
      string[] drives = Directory.GetLogicalDrives();&lt;br /&gt;
      foreach (string s in drives)&lt;br /&gt;
        Console.WriteLine(&amp;quot;--&amp;gt; {0} &amp;quot;, s);&lt;br /&gt;
      try&lt;br /&gt;
      {&lt;br /&gt;
        Directory.Delete(string.Format(@&amp;quot;{0}\MyFolder&amp;quot;, Environment.CurrentDirectory));&lt;br /&gt;
        Directory.Delete(string.Format(@&amp;quot;{0}\MyFolder2&amp;quot;, Environment.CurrentDirectory), true);&lt;br /&gt;
      }&lt;br /&gt;
      catch (IOException e)&lt;br /&gt;
      {&lt;br /&gt;
        Console.WriteLine(e.Message);&lt;br /&gt;
      }&lt;br /&gt;
    }&lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>