Parameters
- destinationDirectoryPath
- The name and path to which to move this directory. The destination cannot be a directory with the identical name. It can be an existing directory to which you want to add this directory as a subdirectory.
Exception | Description |
---|---|
System.ArgumentException | One of the arguments provided to a method is not valid. This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception. |
System.ArgumentNullException |
A This is a usage error, i.e. it will never occur (the exception will not be thrown) in a correctly written program. Your code should not catch this exception. |
System.IO.DirectoryNotFoundException | Part of a file or directory cannot be found. This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately. |
System.IO.IOException | An I/O error has occurred. This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately. |
System.NotSupportedException | An invoked method is not supported at all, or is not supported with the parameters used to create the object. |
System.Security.SecurityException | A security error was detected. This is an operation error that depends on factors external to your program, and thus cannot be always avoided. Your code must handle it appropriately. |
This method is similar in purpose to System.IO.DirectoryInfo.MoveTo(System.String), but is generalized for any kind of writable directory contents, not just files in the physical file system.
You can use this method to rename a directory, keeping it in the same parent directory, too. You need to specify an absolute path in this case (or a relative path that uses navigation above the root). It is recommended to use the IWritableDirectoryContentsExtension.Rename method if your intent is renaming and not moving. The IWritableDirectoryContentsExtension.Rename has additional checks that guarantee that renaming and not moving will occur.
For Microsoft.Extensions.FileProviders.IDirectoryContents, IDirectory2, IDirectoryContents2, IWritableDirectory and IWritableDirectoryContents, relative paths are based on the directory itself; absolute paths are based on the root directory of the file provider. Notice the difference from Microsoft.Extensions.FileProviders.IFileInfo, IFileInfo2 and IWritableFileInfo, where relative paths are based on the directory where the file is located.