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 |
|
System.ArgumentException |
-or-
|
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 |
|
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
-or- The directory is the application's current working directory. -or- The directory specified by -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 |
|
System.ArgumentNullException |
|
System.IO.DirectoryNotFoundException |
-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 |
|
Exceptions
Type | Condition |
---|---|
System.IO.IOException | A file with the same name and location specified by
-or- The directory specified by -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 |
|
System.ArgumentNullException |
|
System.IO.DirectoryNotFoundException |
-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 |
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 |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.ArgumentOutOfRangeException |
|
System.IO.DirectoryNotFoundException |
|
System.IO.IOException |
|
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 |
Exceptions
Type | Condition |
---|---|
System.ArgumentException |
|
System.ArgumentNullException |
|
System.IO.DirectoryNotFoundException |
|
System.IO.IOException |
|
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 |
|
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 |
|
System.ArgumentNullException |
|
System.IO.IOException |
|
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 '', nor can it contain any invalid characters.
Exceptions
Type | Condition |
---|---|
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.ArgumentException |
-or-
|
System.ArgumentNullException |
|
System.ArgumentOutOfRangeException |
|
System.IO.IOException |
|
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 |
-or- A network error has occurred. |
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.ArgumentException |
|
System.ArgumentNullException |
|
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
|
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 '', nor can it contain any invalid characters.
Exceptions
Type | Condition |
---|---|
System.IO.IOException |
-or- A network error has occurred. |
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.ArgumentException |
-or-
|
System.ArgumentNullException |
|
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
|
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 '', nor can it contain any invalid characters.
Exceptions
Type | Condition |
---|---|
System.IO.IOException |
-or- A network error has occurred. |
System.UnauthorizedAccessException | The caller does not have the required permission. |
System.ArgumentException |
-or-
|
System.ArgumentNullException |
|
System.ArgumentOutOfRangeException |
|
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 |
Exceptions
Type | Condition |
---|---|
System.IO.IOException | An attempt was made to move a directory to a different volume. -or-
-or- The -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 |
|
System.ArgumentNullException |
|
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 |
|
System.ArgumentNullException |
|
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. |