FileStore.FileStore.MoveFolder C# (CSharp) Method

MoveFolder() public method

Moves a folder.
public MoveFolder ( string sourcePath, string destinationPath ) : void
sourcePath string The source path.
destinationPath string The destination path.
return void
        public void MoveFolder(string sourcePath, string destinationPath)
        {
            if(sourcePath == null || destinationPath == null) {
                throw new ArgumentNullException("sourcePath | destionationPath");
            }

            string[] sourceComponents = sourcePath.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
            string[] destinationComponents = destinationPath.Split(Separators, StringSplitOptions.RemoveEmptyEntries);

            if(sourceComponents.Length == 0 || destinationComponents.Length == 0) {
                return;
            }

            StoreFolder sourceFolder, sourceFolderParent;
            StoreFolder destinationFolder, destinationFolderParent;

            sourceFolder = GetFolder(sourcePath, out sourceFolderParent);
            destinationFolder = GetFolder(destinationPath, out destinationFolderParent);

            if(sourceFolder == null) {
                // source folder not found
                return;
            }

            if(destinationFolder == null) {
                // create the destination folder
                CreateFolderImpl(destinationPath);
                destinationFolder = GetFolder(destinationPath, out destinationFolderParent);
            }

            // copy all data
            destinationFolder.Files = sourceFolder.Files;
            destinationFolder.Subfolders = sourceFolder.Subfolders;

            // remove source folder
            sourceFolderParent.Subfolders.Remove(sourceFolder.Name);
        }