Show / Hide Table of Contents

Interface IDirectory

Provides methods for working with directories.

Namespace: Terrasoft.IO
Assembly: Terrasoft.IO.dll
Syntax
public interface IDirectory

Methods

Clear(String)

Deletes subdirectories and files in the directory. Resets ReadOnlyAttribute for files. Ensures all subdirectories is successfully deleted.

Declaration
void Clear(string path)
Parameters
Type Name Description
System.String path

The name of the directory to clear.

Remarks

The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed. https://stackoverflow.com/q/24265481

CopyDirectory(String, String)

Declaration
void CopyDirectory(string sourceDirectoryPath, string destinationDirectoryPath)
Parameters
Type Name Description
System.String sourceDirectoryPath
System.String destinationDirectoryPath

CreateDirectory(String)

Creates all directories and subdirectories in the specified path unless they already exist.

Declaration
void CreateDirectory(string path)
Parameters
Type Name Description
System.String path

The directory to create.

Exceptions
Type Condition
System.ArgumentNullException

path is null.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

-or-

path is prefixed with, or contains, only a colon character (:).

System.IO.IOException

The directory specified by path is a file.

-or-

The network name is not known.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

System.NotSupportedException

path contains a colon character (:) that is not part of a drive label ("C:").

CreateOrReplaceDirectory(String)

Deletes the specified directory and any subdirectories and files in the directory and creates an empty directory instead.

Declaration
void CreateOrReplaceDirectory(string path)
Parameters
Type Name Description
System.String path

The path to the directory.

Delete(String)

Deletes an empty directory from a specified path.

Declaration
void Delete(string path)
Parameters
Type Name Description
System.String path

The name of the empty directory to remove. This directory must be writable and empty.

Exceptions
Type Condition
System.IO.IOException

A file with the same name and location specified by path exists.

-or-

The directory is the application's current working directory.

-or-

The directory specified by path is not empty.

-or-

The directory is read-only or contains a read-only file.

-or-

The directory is being used by another process.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

System.ArgumentNullException

path is null.

System.IO.DirectoryNotFoundException

path does not exist or could not be found.

-or-

The specified path is invalid (for example, it is on an unmapped drive).

Delete(String, Boolean)

Deletes the specified directory and, if indicated, any subdirectories and files in the directory.

Declaration
void Delete(string path, bool recursive)
Parameters
Type Name Description
System.String path

The name of the empty directory to remove.

System.Boolean recursive

true to remove directories, subdirectories, and files in path; otherwise, false.

Exceptions
Type Condition
System.IO.IOException

A file with the same name and location specified by path exists.

-or-

The directory specified by path is read-only, or recursive is false and path is not an empty directory.

-or-

The directory is the application's current working directory.

-or-

The directory is read-only or contains a read-only file.

-or-

The directory is being used by another process.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

System.ArgumentNullException

path is null.

System.IO.DirectoryNotFoundException

path does not exist or could not be found.

-or-

The specified path is invalid (for example, it is on an unmapped drive).

EnumerateFiles(String, String, SearchOption)

Returns an enumerable collection of file names that match a search pattern in a specified path, and optionally searches subdirectories.

Declaration
IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption)
Parameters
Type Name Description
System.String path

The relative or absolute path to the directory to search. This string is not case-sensitive.

System.String searchPattern

The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters (see Remarks), but doesn't support regular expressions.

System.IO.SearchOption searchOption

One of the enumeration values that specifies whether the search operation should include only the current directory or should include all subdirectories. The default value is System.IO.SearchOption.TopDirectoryOnly.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

An enumerable collection of the full names (including paths) for the files in the directory specified by path and that match the specified search pattern and option.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method.- or -searchPattern does not contain a valid pattern.

System.ArgumentNullException

path is null.-or-searchPattern is null.

System.ArgumentOutOfRangeException

searchOption is not a valid System.IO.SearchOption value.

System.IO.DirectoryNotFoundException

path is invalid, such as referring to an unmapped drive.

System.IO.IOException

path is a file name.

System.IO.PathTooLongException

The specified path, file name, or combined exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.

System.Security.SecurityException

The caller does not have the required permission.

System.UnauthorizedAccessException

The caller does not have the required permission.

EnumerateFileSystemEntries(String)

Returns an enumerable collection of file names and directory names in a specified path.

Declaration
IEnumerable<string> EnumerateFileSystemEntries(string path)
Parameters
Type Name Description
System.String path

The relative or absolute path to the directory to search. This string is not case-sensitive.

Returns
Type Description
System.Collections.Generic.IEnumerable<System.String>

An enumerable collection of file-system entries in the directory specified by path.

Exceptions
Type Condition
System.ArgumentException

path is a zero-length string, contains only white space, or contains invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method.

System.ArgumentNullException

path is null.

System.IO.DirectoryNotFoundException

path is invalid, such as referring to an unmapped drive.

System.IO.IOException

path is a file name.

System.IO.PathTooLongException

The specified path, file name, or combined exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.

System.Security.SecurityException

The caller does not have the required permission.

System.UnauthorizedAccessException

The caller does not have the required permission.

Exists(String)

Determines whether the given path refers to an existing directory on file system.

Declaration
bool Exists(string path)
Parameters
Type Name Description
System.String path

The path to test.

Returns
Type Description
System.Boolean

true if path refers to an existing directory; false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.

GetCurrentDirectory()

Gets the current working directory of the application.

Declaration
string GetCurrentDirectory()
Returns
Type Description
System.String

A string containing the path of the current working directory.

Exceptions
Type Condition
System.UnauthorizedAccessException

The caller does not have the required permission.

GetDirectories(String)

Returns the names of subdirectories (including their paths) in the specified directory.

Declaration
string[] GetDirectories(string path)
Parameters
Type Name Description
System.String path

The relative or absolute path to the directory to search. This string is not case-sensitive.

Returns
Type Description
System.String[]

An array of the full names (including paths) of subdirectories in the specified path, or an empty array if no directories are found.

Exceptions
Type Condition
System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

System.ArgumentNullException

path is null.

System.IO.IOException

path is a file name.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

GetDirectories(String, String, SearchOption)

Gets an array of directories matching the specified search pattern from the current directory, using a value to determine whether to search subdirectories.

Declaration
string[] GetDirectories(string path, string searchPattern, SearchOption searchOption)
Parameters
Type Name Description
System.String path

The path to search.

System.String searchPattern

The search string to match against the names of subdirectories in path. This parameter can contain a combination of valid literal and wildcard characters, but doesn't support regular expressions.

System.IO.SearchOption searchOption

One of the SearchOption values that specifies whether the search operation should include all subdirectories or only the current directory.

Returns
Type Description
System.String[]

An array of the full names (including paths) of the subdirectories that match the specified criteria, or an empty array if no directories are found.

Remarks

The following wildcard specifiers are permitted in searchPattern.

  • (asterisk) - Zero or more characters in that position. ? (question mark) - Zero or one character in that position. Characters other than the wildcard are literal characters. For example, the searchPattern string "t" searches for all names in path ending with the letter "t". The searchPattern string "s" searches for all names in path beginning with the letter "s". searchPattern cannot end in two periods ("..") or contain two periods ("..") followed by '/' or '&apos;, nor can it contain any invalid characters.
Exceptions
Type Condition
System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

-or-

searchPattern does not contain a valid pattern.

System.ArgumentNullException

path or searchPattern is null.

System.ArgumentOutOfRangeException

searchOption is not a valid System.IO.SearchOption value.

System.IO.IOException

path is a file name.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

GetDirectoryInfo(String)

Returns instance of System.IO.DirectoryInfo.

Declaration
IDirectoryInfo GetDirectoryInfo(string path)
Parameters
Type Name Description
System.String path

Path to directory.

Returns
Type Description
IDirectoryInfo

GetFiles(String)

Returns full path names of the files in the specified directory.

Declaration
string[] GetFiles(string path)
Parameters
Type Name Description
System.String path

The relative or absolute path to the directory to search. This string is not case-sensitive.

Returns
Type Description
System.String[]

Array of the full-path file names in the specified directory. Returns empty array if no files found.

Exceptions
Type Condition
System.IO.IOException

path is a file name.

-or-

A network error has occurred.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

System.ArgumentNullException

path is null.

System.IO.DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

GetFiles(String, String)

Returns full path names of the files that match the specified search pattern in the specified directory.

Declaration
string[] GetFiles(string path, string searchPattern)
Parameters
Type Name Description
System.String path

The relative or absolute path to the directory to search. This string is not case-sensitive.

System.String searchPattern

The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but doesn't support regular expressions.

Returns
Type Description
System.String[]

An array of the full-path file names in the specified directory that match the specified search pattern or an empty array if no files found.

Remarks

The following wildcard specifiers are permitted in searchPattern.

  • (asterisk) - Zero or more characters in that position. ? (question mark) - Zero or one character in that position. Characters other than the wildcard are literal characters. For example, the searchPattern string "t" searches for all names in path ending with the letter "t". The searchPattern string "s" searches for all names in path beginning with the letter "s". searchPattern cannot end in two periods ("..") or contain two periods ("..") followed by '/' or '&apos;, nor can it contain any invalid characters.
Exceptions
Type Condition
System.IO.IOException

path is a file name.

-or-

A network error has occurred.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

-or-

searchPattern does not contain a valid pattern.

System.ArgumentNullException

path or searchPattern is null.

System.IO.DirectoryNotFoundException

The specified path is not found or invalid (for example, it is on an unmapped drive).

GetFiles(String, String, SearchOption)

Returns full path names of the files that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories.

Declaration
string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
Parameters
Type Name Description
System.String path

The relative or absolute path to the directory to search. This string is not case-sensitive.

System.String searchPattern

The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but doesn't support regular expressions.

System.IO.SearchOption searchOption

One of the enumeration values that specifies whether the search operation should include all subdirectories or only the current directory.

Returns
Type Description
System.String[]

An array of the full-path file names in the specified directory that match the specified search pattern and option or an empty array if no files found.

Remarks

The following wildcard specifiers are permitted in searchPattern.

  • (asterisk) - Zero or more characters in that position. ? (question mark) - Zero or one character in that position. Characters other than the wildcard are literal characters. For example, the searchPattern string "t" searches for all names in path ending with the letter "t". The searchPattern string "s" searches for all names in path beginning with the letter "s". searchPattern cannot end in two periods ("..") or contain two periods ("..") followed by '/' or '&apos;, nor can it contain any invalid characters.
Exceptions
Type Condition
System.IO.IOException

path is a file name.

-or-

A network error has occurred.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

-or-

searchPattern does not contain a valid pattern.

System.ArgumentNullException

path or searchPattern is null.

System.ArgumentOutOfRangeException

searchOption is not a valid System.IO.SearchOption value.

System.IO.DirectoryNotFoundException

The specified path is not found or invalid (for example, it is on an unmapped drive).

Move(String, String)

Moves a file or a directory and its contents to a new location.

Declaration
void Move(string sourceDirName, string destDirName)
Parameters
Type Name Description
System.String sourceDirName

The path of the file or directory to move.

System.String destDirName

The path to the new location for sourceDirName. If sourceDirName is a file, then destDirName must also be a file name.

Exceptions
Type Condition
System.IO.IOException

An attempt was made to move a directory to a different volume.

-or-

destDirName already exists.

-or-

The sourceDirName and destDirName parameters refer to the same file or directory.

-or-

The directory or a file within it is being used by another process.

System.UnauthorizedAccessException

The caller does not have the required permission.

System.ArgumentException

sourceDirName or destDirName is a zero-length string, contains only white space, or contains one or more invalid characters.

System.ArgumentNullException

sourceDirName or destDirName is null.

System.IO.DirectoryNotFoundException

The specified path is not found or invalid (for example, it is on an unmapped drive).

SafeDelete(String)

Deletes the specified directory and any subdirectories and files in the directory. Resets ReadOnlyAttribute for files. Ensures directory and all subdirectories is successfully deleted.

Declaration
void SafeDelete(string path)
Parameters
Type Name Description
System.String path

The name of the directory to remove.

Remarks

The RemoveDirectory function marks a directory for deletion on close. Therefore, the directory is not removed until the last handle to the directory is closed. https://stackoverflow.com/q/24265481

SetCurrentDirectory(String)

Sets the application's current working directory to the specified directory.

Declaration
void SetCurrentDirectory(string path)
Parameters
Type Name Description
System.String path

The path to which the current working directory is set.

Exceptions
Type Condition
System.IO.IOException

An I/O error occurred.

System.ArgumentException

path is a zero-length string, contains only white space, or contains one or more invalid characters.

System.ArgumentNullException

path is null.

System.Security.SecurityException

The caller does not have the required permission to access unmanaged code.

System.IO.FileNotFoundException

The specified path was not found.

System.IO.DirectoryNotFoundException

The specified directory was not found.

Extension Methods

ReflectionUtilities.GetPropertyValue(Object, String)
ReflectionUtilities.GetPropertyDefValue(Object, String, Object)
ReflectionUtilities.TryGetPropertyValue(Object, String, out Object)
ReflectionUtilities.HasProperty(Object, String)
ReflectionUtilities.GetPropertyValue(Object, String, BindingFlags)
ReflectionUtilities.GetPropertyValueByPath(Object, String)
ReflectionUtilities.SetPropertyValue(Object, String, Object)
ReflectionUtilities.TrySetPropertyValue(Object, String, Object)
ValidateUtilities.CheckArgumentNull(Object, String)
ValidateUtilities.CheckDependencyNull(Object, String)
ValidateUtilities.EnsureDependencyNotNull<T>(T, String)
MetaDataTestUtils.MetaPropertiesShouldNotHaveDefValue<TInstance>(TInstance)
MetaDataTestUtils.MetaPropertiesShouldNotHaveDefValue<TInstance>(TInstance, Boolean)
NSubstituteExtension.Protected(Object, String, Object[])
NSubstituteExtension.Protected(Object, String, Boolean, Object[])
NSubstituteExtension.ProtectedGeneric<T>(Object, String, Object[])
NSubstituteExtension.ProtectedGeneric<T>(Object, String, Boolean, Object[])
NSubstituteExtension.ProtectedProperty(Object, String)
NSubstituteExtension.MatchInstance<T>(T)
SubstituteUtilities.GetIsSubstituteObject(Object)
SubstituteUtilities.Instead<TInstance, TValue>(TInstance, Func<TInstance, TValue>)
Back to top Generated by DocFX