Manipulate a Filename

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.

Discussion

File paths are often difficult to work with in code because there are an unlimited number of 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 relative paths (c:\ temp\ myfiles\..\ or c:\temp\myfiles\..\..\temp). This is especially the case if you want the user to supply a file or path value. In this case, the user could specify a relative path that points to an operating system file. If your code doesn’t detect the problem, sensitive information ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook 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.