Directory Class

Exposes static methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.

Syntax

Declaration

[ComVisible(true)]
public static class Directory

Inheritance Hierarchy

Inherited Members

System.Object

, , , , , ,

Methods summary

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

Deletes an empty directory from a specified path.

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

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

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

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

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

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

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

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

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

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

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

Gets the creation date and time of a directory.

Gets the creation date and time, in Coordinated Universal Time (UTC) format, of a directory.

Gets the current working directory of the application.

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

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

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

Returns the volume information, root information, or both for the specified path.

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

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

Returns the names of files (including their paths) that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories.

Returns the names of all files and subdirectories in a specified path.

Returns an array of file names and directory names that that match a search pattern in a specified path.

Returns an array of all the file names and directory names that match a search pattern in a specified path, and optionally searches subdirectories.

Returns the date and time the specified file or directory was last accessed.

Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or directory was last accessed.

Returns the date and time the specified file or directory was last written to.

Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or directory was last written to.

Retrieves the parent directory of the specified path, including both absolute and relative paths.

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

Sets the creation date and time for the specified file or directory.

Sets the creation date and time, in Coordinated Universal Time (UTC) format, for the specified file or directory.

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

Sets the date and time the specified file or directory was last accessed.

Sets the date and time, in Coordinated Universal Time (UTC) format, that the specified file or directory was last accessed.

Sets the date and time a directory was last written to.

Sets the date and time, in Coordinated Universal Time (UTC) format, that a directory was last written to.

Methods

  • CreateDirectory(String)

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

    public static DirectoryInfo CreateDirectory(string path)

    Parameters

    • path

      The directory to create.

    Returns

    • An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.

    Exceptions

    • The directory specified by path is a file.

      -or-

      The network name is not known.

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.

      -or-

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

    • path is null.

    • The specified path, file name, or both 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.

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

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

  • Delete(String)

    Deletes an empty directory from a specified path.

    public static void Delete(string path)

    Parameters

    • path

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

    Exceptions

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

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.

    • path is null.

    • The specified path, file name, or both 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.

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

    public static void Delete(string path, bool recursive)

    Parameters

    • path

      The name of the directory to remove.

    • recursive

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

    Exceptions

    • 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 contains a read-only file.

      -or-

      The directory is being used by another process.

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.

    • path is null.

    • The specified path, file name, or both 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.

    • path does not exist or could not be found.

      -or-

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

  • EnumerateDirectories(String)

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

    public static IEnumerable<string> EnumerateDirectories(string path)

    Parameters

    • path

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

    Returns

    • An enumerable collection of the full names (including paths) for the directories in the directory specified by path.

    Exceptions

  • EnumerateDirectories(String, String)

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

    public static IEnumerable<string> EnumerateDirectories(string path, string searchPattern)

    Parameters

    • path

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

    • searchPattern

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

    Returns

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

    Exceptions

    • path is a zero-length string, contains only white space, or contains invalid characters. You can query for invalid characters with the GetInvalidPathChars() method.

      - or -

      searchPattern does not contain a valid pattern.

    • path is null.

      -or-

      searchPattern is null.

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

    • path is a file name.

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

    • The caller does not have the required permission.

    • The caller does not have the required permission.

  • 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 static IEnumerable<string> EnumerateDirectories(string path, string searchPattern, SearchOption searchOption)

    Parameters

    • path

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

    • searchPattern

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

    • 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 TopDirectoryOnly.

    Returns

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

    Exceptions

  • EnumerateFiles(String)

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

    public static IEnumerable<string> EnumerateFiles(string path)

    Parameters

    • path

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

    Returns

    • An enumerable collection of the full names (including paths) for the files in the directory specified by path.

    Exceptions

  • EnumerateFiles(String, String)

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

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

    Parameters

    • path

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

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

    Returns

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

    Exceptions

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

      - or -

      searchPattern does not contain a valid pattern.

    • path is null.

      -or-

      searchPattern is null.

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

    • path is a file name.

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

    • The caller does not have the required permission.

    • The caller does not have the required permission.

  • EnumerateFiles(String, String, SearchOption)

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

    public static IEnumerable<string> EnumerateFiles(string path, string searchPattern, SearchOption searchOption)

    Parameters

    • path

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

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

    • 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 TopDirectoryOnly.

    Returns

    • 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

  • EnumerateFileSystemEntries(String)

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

    public static IEnumerable<string> EnumerateFileSystemEntries(string path)

    Parameters

    • path

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

    Returns

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

    Exceptions

  • EnumerateFileSystemEntries(String, String)

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

    public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern)

    Parameters

    • path

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

    • searchPattern

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

    Returns

    • An enumerable collection of file-system entries in the directory specified by path and that match the specified search pattern.

    Exceptions

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

      - or -

      searchPattern does not contain a valid pattern.

    • path is null.

      -or-

      searchPattern is null.

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

    • path is a file name.

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

    • The caller does not have the required permission.

    • The caller does not have the required permission.

  • EnumerateFileSystemEntries(String, String, SearchOption)

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

    public static IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, SearchOption searchOption)

    Parameters

    • path

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

    • searchPattern

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

    • 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 TopDirectoryOnly.

    Returns

    • An enumerable collection of file-system entries in the directory specified by path and that match the specified search pattern and option.

    Exceptions

  • Exists(String)

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

    public static bool Exists(string path)

    Parameters

    • path

      The path to test.

    Returns

    • 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 file exists.

  • GetCreationTime(String)

    Gets the creation date and time of a directory.

    public static DateTime GetCreationTime(string path)

    Parameters

    • path

      The path of the directory.

    Returns

    • A structure that is set to the creation date and time for the specified directory. This value is expressed in local time.

    Exceptions

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.

    • path is null.

    • The specified path, file name, or both 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.

  • GetCreationTimeUtc(String)

    Gets the creation date and time, in Coordinated Universal Time (UTC) format, of a directory.

    public static DateTime GetCreationTimeUtc(string path)

    Parameters

    • path

      The path of the directory.

    Returns

    • A structure that is set to the creation date and time for the specified directory. This value is expressed in UTC time.

    Exceptions

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.

    • path is null.

    • The specified path, file name, or both 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.

  • GetCurrentDirectory()

    Gets the current working directory of the application.

    public static string GetCurrentDirectory()

    Returns

    • A string that contains the path of the current working directory, and does not end with a backslash ().

    Exceptions

    • The caller does not have the required permission.

    • The operating system is Windows CE, which does not have current directory functionality.

      This method is available in the .NET Compact Framework, but is not currently supported.

  • GetDirectories(String)

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

    public static string[] GetDirectories(string path)

    Parameters

    • path

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

    Returns

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

    Exceptions

  • GetDirectories(String, String)

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

    public static string[] GetDirectories(string path, string searchPattern)

    Parameters

    • path

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

    • 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 (see Remarks), but doesn't support regular expressions.

    Returns

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

    Exceptions

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using GetInvalidPathChars().

      -or-

      searchPattern doesn't contain a valid pattern.

    • path or searchPattern is null.

    • The specified path, file name, or both 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.

    • path is a file name.

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

  • GetDirectories(String, String, SearchOption)

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

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

    Parameters

    • path

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

    • 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 (see Remarks), but doesn't support regular expressions.

    • searchOption

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

    Returns

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

    Exceptions

  • GetDirectoryRoot(String)

    Returns the volume information, root information, or both for the specified path.

    public static string GetDirectoryRoot(string path)

    Parameters

    • path

      The path of a file or directory.

    Returns

    • A string that contains the volume information, root information, or both for the specified path.

    Exceptions

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters with GetInvalidPathChars().

    • path is null.

    • The specified path, file name, or both 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.

  • GetFiles(String)

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

    public static string[] GetFiles(string path)

    Parameters

    • path

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

    Returns

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

    Exceptions

    • path is a file name.

      -or-

      A network error has occurred.

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the GetInvalidPathChars() method.

    • path is null.

    • The specified path, file name, or both 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.

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

  • GetFiles(String, String)

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

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

    Parameters

    • path

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

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

    Returns

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

    Exceptions

    • path is a file name.

      -or-

      A network error has occurred.

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using GetInvalidPathChars().

      -or-

      searchPattern doesn't contain a valid pattern.

    • path or searchPattern is null.

    • The specified path, file name, or both 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.

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

  • GetFiles(String, String, SearchOption)

    Returns the names of files (including their paths) that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories.

    public static string[] GetFiles(string path, string searchPattern, SearchOption searchOption)

    Parameters

    • path

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

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

    • searchOption

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

    Returns

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

    Exceptions

  • GetFileSystemEntries(String)

    Returns the names of all files and subdirectories in a specified path.

    public static string[] GetFileSystemEntries(string path)

    Parameters

    • path

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

    Returns

    • An array of the names of files and subdirectories in the specified directory, or an empty array if no files or subdirectories are found.

    Exceptions

  • GetFileSystemEntries(String, String)

    Returns an array of file names and directory names that that match a search pattern in a specified path.

    public static string[] GetFileSystemEntries(string path, string searchPattern)

    Parameters

    • path

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

    • searchPattern

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

    Returns

    • An array of file names and directory names that match the specified search criteria, or an empty array if no files or directories are found.

    Exceptions

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters with the GetInvalidPathChars() method.

      -or-

      searchPattern does not contain a valid pattern.

    • path or searchPattern is null.

    • The specified path, file name, or both 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.

    • path is a file name.

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

  • GetFileSystemEntries(String, String, SearchOption)

    Returns an array of all the file names and directory names that match a search pattern in a specified path, and optionally searches subdirectories.

    public static string[] GetFileSystemEntries(string path, string searchPattern, SearchOption searchOption)

    Parameters

    • path

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

    • searchPattern

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

    • 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 TopDirectoryOnly.

    Returns

    • An array of file the file names and directory names that match the specified search criteria, or an empty array if no files or directories are found.

    Exceptions

  • GetLastAccessTime(String)

    Returns the date and time the specified file or directory was last accessed.

    public static DateTime GetLastAccessTime(string path)

    Parameters

    • path

      The file or directory for which to obtain access date and time information.

    Returns

    • A structure that is set to the date and time the specified file or directory was last accessed. This value is expressed in local time.

    Exceptions

  • GetLastAccessTimeUtc(String)

    Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or directory was last accessed.

    public static DateTime GetLastAccessTimeUtc(string path)

    Parameters

    • path

      The file or directory for which to obtain access date and time information.

    Returns

    • A structure that is set to the date and time the specified file or directory was last accessed. This value is expressed in UTC time.

    Exceptions

  • GetLastWriteTime(String)

    Returns the date and time the specified file or directory was last written to.

    public static DateTime GetLastWriteTime(string path)

    Parameters

    • path

      The file or directory for which to obtain modification date and time information.

    Returns

    • A structure that is set to the date and time the specified file or directory was last written to. This value is expressed in local time.

    Exceptions

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters with the GetInvalidPathChars() method.

    • path is null.

    • The specified path, file name, or both 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.

  • GetLastWriteTimeUtc(String)

    Returns the date and time, in Coordinated Universal Time (UTC) format, that the specified file or directory was last written to.

    public static DateTime GetLastWriteTimeUtc(string path)

    Parameters

    • path

      The file or directory for which to obtain modification date and time information.

    Returns

    • A structure that is set to the date and time the specified file or directory was last written to. This value is expressed in UTC time.

    Exceptions

    • The caller does not have the required permission.

    • path is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters with the GetInvalidPathChars() method.

    • path is null.

    • The specified path, file name, or both 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.

  • GetParent(String)

    Retrieves the parent directory of the specified path, including both absolute and relative paths.

    public static DirectoryInfo GetParent(string path)

    Parameters

    • path

      The path for which to retrieve the parent directory.

    Returns

    • The parent directory, or null if path is the root directory, including the root of a UNC server or share name.

    Exceptions

  • Move(String, String)

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

    public static void Move(string sourceDirName, string destDirName)

    Parameters

    • sourceDirName

      The path of the file or directory to move.

    • destDirName

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

    Exceptions

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

    • The caller does not have the required permission.

    • sourceDirName or destDirName is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters with the GetInvalidPathChars() method.

    • sourceDirName or destDirName is null.

    • The specified path, file name, or both 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.

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

  • SetCreationTime(String, DateTime)

    Sets the creation date and time for the specified file or directory.

    public static void SetCreationTime(string path, DateTime creationTime)

    Parameters

    • path

      The file or directory for which to set the creation date and time information.

    • creationTime

      The date and time the file or directory was last written to. This value is expressed in local time.

    Exceptions

  • SetCreationTimeUtc(String, DateTime)

    Sets the creation date and time, in Coordinated Universal Time (UTC) format, for the specified file or directory.

    public static void SetCreationTimeUtc(string path, DateTime creationTimeUtc)

    Parameters

    • path

      The file or directory for which to set the creation date and time information.

    • creationTimeUtc

      The date and time the directory or file was created. This value is expressed in local time.

    Exceptions

  • SetCurrentDirectory(String)

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

    [SecurityCritical]
    public static void SetCurrentDirectory(string path)

    Parameters

    • path

      The path to which the current working directory is set.

    Exceptions

  • SetLastAccessTime(String, DateTime)

    Sets the date and time the specified file or directory was last accessed.

    public static void SetLastAccessTime(string path, DateTime lastAccessTime)

    Parameters

    • path

      The file or directory for which to set the access date and time information.

    • lastAccessTime

      An object that contains the value to set for the access date and time of path. This value is expressed in local time.

    Exceptions

  • SetLastAccessTimeUtc(String, DateTime)

    Sets the date and time, in Coordinated Universal Time (UTC) format, that the specified file or directory was last accessed.

    public static void SetLastAccessTimeUtc(string path, DateTime lastAccessTimeUtc)

    Parameters

    • path

      The file or directory for which to set the access date and time information.

    • lastAccessTimeUtc

      An object that contains the value to set for the access date and time of path. This value is expressed in UTC time.

    Exceptions

  • SetLastWriteTime(String, DateTime)

    Sets the date and time a directory was last written to.

    public static void SetLastWriteTime(string path, DateTime lastWriteTime)

    Parameters

    • path

      The path of the directory.

    • lastWriteTime

      The date and time the directory was last written to. This value is expressed in local time.

    Exceptions

  • SetLastWriteTimeUtc(String, DateTime)

    Sets the date and time, in Coordinated Universal Time (UTC) format, that a directory was last written to.

    public static void SetLastWriteTimeUtc(string path, DateTime lastWriteTimeUtc)

    Parameters

    • path

      The path of the directory.

    • lastWriteTimeUtc

      The date and time the directory was last written to. This value is expressed in UTC time.

    Exceptions

Details

Namespace

System.IO

Assembly

System.IO.FileSystem.dll

See Also