This project has moved. For the latest updates, please go here.

System.IO.DirectoryInfo Extension Methods

DirectoryInfo.CreateDirectory Method

A DirectoryInfo extension method that creates a directory and all subdirectories.

Syntax

void CreateDirectory(DirectoryInfo @this)

Parameters

@this
The @this to act on.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 using Z;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_IO_DirectoryInfo_CreateDirectory
     {
         [TestMethod]
         public void CreateDirectory()
         {
             string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "System_IO_DirectoryInfo_CreateDirectory", "SubDirectory");
 
             // Type
             var @this = new DirectoryInfo(path);
 
             // Examples
             @this.CreateDirectory(); // Create directory and subdirectory
 
             // Unit Test
             Assert.IsTrue(path.ToDirectoryInfo().Exists);
         }
     }
 }
                

DirectoryInfo.GetDirectories Method

A DirectoryInfo extension method that search for all directories.

Syntax

DirectoryInfo[] GetDirectories(DirectoryInfo @this,SearchOption searchOption)

Parameters

@this
The @this to act on.
searchOption
(Optional) the search option.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_IO_DirectoryInfo_GetDirectories
     {
         [TestMethod]
         public void GetDirectories()
         {
             string path = AppDomain.CurrentDomain.BaseDirectory;
 
             // Type
             var @this = new DirectoryInfo(path);
 
             // Examples
             var value1 = @this.GetDirectories(); // Obsolete!
 
             // Unit Test
         }
     }
 }
                

DirectoryInfo.GetFiles Method

A DirectoryInfo extension method that search for all files.

Syntax

FileInfo[] GetFiles(DirectoryInfo @this,SearchOption searchOption)

Parameters

@this
The @this to act on.
searchOption
(Optional) the search option.

Examples


 // Copyright (c) 2013 Jonathan Magnan (http://zzzportal.com)
 // All rights reserved.
 // Licensed under MIT License (MIT)
 // License can be found here: https://zextensionmethods.codeplex.com/license
 
 using System;
 using System.IO;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace ExtensionMethods.Examples
 {
     [TestClass]
     public class System_IO_DirectoryInfo_GetFiles
     {
         [TestMethod]
         public void GetFiles()
         {
             string path = AppDomain.CurrentDomain.BaseDirectory;
 
             // Type
             var @this = new DirectoryInfo(path);
 
             // Examples
             var value1 = @this.GetFiles(); // Obsolete!
 
             // Unit Test
         }
     }
 }
                

Last edited Nov 23, 2013 at 7:54 PM by Jonathan_Magnan, version 1