Move a folder to another in C# In C# I wrote a method to move a folder into another existing folder:

public void MoveFolder(string folderToMove, string destination)
{
    String destinationFolder = Path.Combine(
        destination, Path.GetFileName(folderToMove));

    Directory.Move(folderToMove, destinationFolder);
}


Usage:

MoveFolder(@"D:\myfolder\mysubfolder", @"C:\");


It works, but I am sure there is a more readable and shorter way to do that? In particular, I feel bad using GetFileName.


No tricky things to worry about: The folders exist, and destination is not inside folderToMove nor the same.
It must work on .NET 4.0 without additional libraries.
This method is public but you don't do any validation about the passed in parameters which is a bad idea because your code is giving implementationdetails to a user of that method which he/she doesn't need to know. Assume folderToMove == null  then PathCombine() will throw an ArgumentNullException which is the correct exception, but this is telling a user that you are using System.Path.Combine() which he/she doesn't need to know.  

You should better do the validation yourself and throw the expected exception.   



Instead of Path.GetFileName() you should use a DirectoryInfo object and read its Name property which you could extract to a separate method to construct the destination foldername like so  

    public void MoveFolder(string folderToMove, string destination)
    {
        if (folderToMove == null)
        {
            throw new ArgumentNullException("folderToMove");
        }
        if (destination == null)
        {
            throw new ArgumentNullException("destination");
        }
        if (string.IsNullOrEmpty(folderToMove))
        {
            throw new ArgumentException("The parameter may not be empty", "folderToMove");
        }
        if (string.IsNullOrEmpty(destination))
        {
            throw new ArgumentException("The parameter may not be empty", "destination");
        }

        String destinationFolder = CreateDestinationFolderName(folderToMove, destination);
        Directory.Move(folderToMove, destinationFolder);
    }
    private string CreateDestinationFolderName(string folderToMove, string destination)
    {
        var directoryInfo = new DirectoryInfo(folderToMove);

        return Path.Combine(destination, directoryInfo.Name);
    }