Just do one thing. From screenshot above you can see that we can use the immediate panel while debugging (set a breakpoint and get paused) for exploring statements. So you can test and check the different statements that you have in your mind.
For the question we gave the recommendation to use Path.GetFileNameWithoutExtension method