Table of Contents

Class Directory

Namespace
Kentico.Xperience.AmazonStorage
Assembly
Kentico.Xperience.AmazonStorage.dll

Implementation of Directory class for Amazon S3.

public class Directory : AbstractDirectory
Inheritance
object
Directory
Inherited Members
Extension Methods

Constructors

Directory()

Initializes a new instance of the Directory class, which provides operations with directories.

public Directory()

Methods

CreateDirectory(string)

Creates all directories and subdirectories as specified by path.

public override DirectoryInfo CreateDirectory(string path)

Parameters

path string

Path to create.

Returns

DirectoryInfo

Remarks

The object representing the directory is created whenever it is missing, even when the directory is already represented by objects stored under its path, so that its existence is answered by its own object afterwards without probing its key prefix, see ExistsInS3Storage(string).

Delete(string)

Deletes an empty directory.

public override void Delete(string path)

Parameters

path string

Path to directory

Delete(string, bool)

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

public override void Delete(string path, bool recursive)

Parameters

path string

Path to directory

recursive bool

Deletes all sub directories in given path.

Exceptions

DirectoryNotFoundException

Thrown when path does not exist.

IOException

Thrown when path refers to the root of the storage, or when it is not empty and recursive is false.

DeleteDirectoryStructure(string)

Deletes all files in the directory structure. It works also in a shared hosting environment.

public override void DeleteDirectoryStructure(string path)

Parameters

path string

Full path of the directory to delete

EnumerateDirectories(string, string, SearchOption)

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

public override IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption)

Parameters

path string

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

searchPattern string

Search pattern.

searchOption SearchOption

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

Returns

IEnumerable<string>

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

EnumerateFiles(string, string)

Returns an enumerable collection of file names that match a search pattern in a specified path.

public override IEnumerable<string> EnumerateFiles(string path, string searchPattern)

Parameters

path string

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

searchPattern string

Search pattern.

Returns

IEnumerable<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.

Exists(string)

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

public override bool Exists(string path)

Parameters

path string

Path to test.

Returns

bool

Remarks

In line with the System.IO.Directory.Exists(string) contract of not throwing for invalid input, a path navigating above its own root is reported as non-existent, because it cannot address any object.

ExistsInFileSystem(string)

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

public static bool ExistsInFileSystem(string path)

Parameters

path string

Path to test.

Returns

bool

ExistsInS3Storage(string)

Determines whether the given path refers to an existing directory on Amazon S3 storage.

public static bool ExistsInS3Storage(string path)

Parameters

path string

Path to test.

Returns

bool

Remarks

A directory exists when it is represented by its own object or when any object is stored under its path, the same way the directory is listed by GetDirectories(string, string, SearchOption). The result of the key prefix probe is cached together with the directory listings, see Kentico.Xperience.AmazonStorage.S3ObjectInfoProvider.AnyObjectExistsUnderPrefix(System.String).

GetDirectories(string, string, SearchOption)

Gets the names of the subdirectories (including their paths) that match the specified search pattern in the current directory, and optionally searches subdirectories.

public override string[] GetDirectories(string path, string searchPattern, SearchOption searchOption)

Parameters

path string

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

searchPattern string

Search pattern.

searchOption SearchOption

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

Returns

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.

GetFiles(string, string)

Returns the names of files (including their paths) that match the specified search pattern in the specified directory.

public override string[] GetFiles(string path, string searchPattern)

Parameters

path string

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

searchPattern string

Search pattern.

Returns

string[]

An array of the full names (including paths) for the files in the specified directory that match the specified search pattern, or an empty array if no files are found.

Move(string, string)

Moves directory.

public override void Move(string sourceDirName, string destDirName)

Parameters

sourceDirName string

Source directory name.

destDirName string

Destination directory name.

Remarks

The move is implemented as a copy of the objects followed by their deletion. The objects of a directory are deleted from the source directory only after all of them were copied to the destination directory.

Unlike System.IO.Directory.Move(string, string), an existing destination directory is allowed. The content of the source directory is merged into it and files of the same name are overwritten.

A source directory existing in the local file system is deleted from there only when it does not exist in the storage and the fallback to the local file system is enabled. Otherwise its local content is uploaded to the destination directory and retained in the local file system.

Exceptions

DirectoryNotFoundException

Thrown when sourceDirName does not exist.

IOException

Thrown when destDirName refers to sourceDirName or is located inside it.