
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
716
|
Chapter 12: Filesystem I/O
GetFileName
This method returns the filename, including the file extension. If no filename is
provided in the path, this method returns an empty string, not
null.
GetExtension
This method returns the file’s extension. If no extension is provided for the file
or no file exists in the path, this method returns an empty string, not
null.
GetFileNameWithoutExtension
This method returns the root filename without the file extension.
Be aware that these methods do not actually determine whether the drives, directo-
ries, or even files exist on the system that runs these methods. These methods are
string parsers and if you pass one of them a string in some strange format (such as
\\ZY:\foo), it will try to do what it can with it anyway:
ParsePath of \\ZY:\foo breaks up into the following pieces:
Root: \\ZY:\foo
Directory Name:
Full File Name: foo
File Extension:
File Name Without Extension: foo
These methods will, however, throw an exception if illegal characters are found in
the path.
To determine whether files or directories exist, use the static
Directory.Exists or
File.Exists method.
See Also
See the “Path Class” topic in the MSDN documentation.
12.16 Parsing Paths in Environment Variables
Problem
You need to parse multiple paths contained in environment variables, ...