Walter.IO
Swap Method
Example 
Walter.IO Assembly > Walter.IO Namespace > AppDataDirectory Class : Swap Method
The path to the new directory that will become the working directory. This path must not be null or empty.
Specifies the action to take on the files in the current directory when swapping to the new directory.
Swaps the current working directory with a new directory, optionally moving or deleting the files in the original directory.
Syntax

Parameters

newPath
The path to the new directory that will become the working directory. This path must not be null or empty.
option
Specifies the action to take on the files in the current directory when swapping to the new directory.
Remarks
This method changes the application's current working directory to newPath. Depending on the option specified, it can also move or delete the existing files within the original directory. If newPath is the same as the current directory path (ignoring case), the method performs no action and ignores the option parameter. This operation is particularly useful for applications that need to dynamically manage file storage locations, such as when archiving files or transitioning to a new storage directory.

Available option values:

Note: If the directory specified by newPath does not exist, it will be created automatically. If option includes SwapDirectoryOptions.Move and the new directory is outside the original path, the entire original directory will be deleted after the files are handled according to option.
Example
This example demonstrates how to swap to a new working directory while moving all files from the old directory to the new one.
var directoryManager = new DirectoryManager();
string currentPath = directoryManager.CurrentPath;
string newPath = @"C:\NewDirectory";
            
directoryManager.Swap(newPath, SwapDirectoryOptions.Copy);
            
Console.WriteLine($"Directory swapped from {currentPath} to {newPath}, with all files moved.");
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

AppDataDirectory Class
AppDataDirectory Members