5.13. Manipulate Strings Representing File Names
Problem
You want to retrieve a portion of a path or verify that a file path is in a normal (standardized) form.
Solution
Process the path using the System.IO.Path class. You can use Path.GetFileName to retrieve a file name from a path, Path.ChangeExtension to modify the extension portion of a path string, and Path.Combine to create a fully qualified path without worrying about whether your directory includes a trailing directory separation (\) character.
How It Works
File paths are often difficult to work with in code because of the many different ways to represent the same directory. For example, you might use an absolute path (C:\Temp), a UNC path (\\MyServer\\MyShare\temp), or one of many possible ...
Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.