Problem
I am developing a WinForm application using C# and I want to copy a file from one directory to another using System.IO.File.Copy(). I have the file's full path, including file name. I need to extract the file name out of this string. What is the easiest way to do this?
Solution
Of course, the first thing that came to mind was using regular expressions, or perhaps finding the index of the last backslash and removing all of the charcters using the string object's Remove function. However, this all seemed like too much work.
I decided to do a quick search on Google and found out from here that C# let's you simply do this:
System.IO.Path.GetFileName(filePath);
Fantasticly simple!