Q:

C# Split File Name Beginner Exercise

I have a directory filled with multiple excel files that I would like to rename. The names all have leading integers and a '-'. For example: 0123456-Test_01. I would like to rename all of the files within this directory by removing this prefix. 0123456-Test_01 should just be Test_01. I can rename a hard coded instance of a string, but am having trouble getting the files and renaming all of them.
My code is below. Any help is appreciated, as I am clearly new to C#.
public static void Main()
{
    //Successfully splits hardcoded string
    var temp = "0005689-Test_01".Split('-');
    Console.WriteLine(temp[1]);
    Console.ReadLine();

    //Unsuccessful renaming of all files within directory
    List<string> files = System.IO.Directory.GetFiles(@"C:\Users\acars\Desktop\B", "*").ToList();
    System.IO.File.Move(@"C:\Users\acars\Desktop\B\", @"C:\Users\acars\Desktop\B\".Split('-'));

    foreach (string file in files)
    {
        var temp = files.Split('-');
        return temp[1];
    };            
}

A:

There are some errors to fix in your code. 
The first one is the wrong usage of the variable files. This is the full list of files, not the single file that you want to split and move. As explained comments you should use the iterator result stored in the variable file
The most important problem is the fact that the File.Move method throws an exception if the destination file exists. After removing the first part of your filename string, you cannot be sure that the resulting name is unique in your directory.
So a check for the existance of the file before the Move is mandatory.
Finally, it is better use Directory.EnumerateFiles because this method allows you to start the execution of your moving code without loading first all filenames in memory in a list. (In a folder full of files this could make a noticeable difference in speed)
public static void Main()
{
     string workPath = @"C:\Users\acars\Desktop\B";
     foreach (string file in Directory.EnumerateFiles(workPath)
     {
         string[] temp = file.Split('-');
         if(temp.Length > 1)
         {
             string newName = Path.Combine(workPath, temp[1]);
             if(!File.Exists(newName))
                File.Move(file, newName);
         }
     }
 }

Pay also attention to the comment below from CodeNotFound. You are using an hard-coded path so the problem actually doesn't exist, but if the directory contains a single "-" in its name then you should use something like this to get the last element in the splitted array
 string newName = Path.Combine(workPath, temp[temp.Length-1]);

