0% found this document useful (0 votes)
12 views1 page

Complete-Reference-Vb Net 38

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Complete-Reference-Vb Net 38

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

The File Class

Move Moves the source file to a new folder. It also provides the option of a new
filename
Open Opens a FileStream on the given path
OpenRead Opens an existing file for reading
OpenText Opens an existing UTF−8 encoded text file for reading
OpenWrite Opens an existing file for writing
SetAttributes Sets the specified FileAttributes on the file on the given path
SetCreationTime Sets the date and time that the file was created
SetLastAccessTime Sets the date and time that the given file was last accessed
SetLastWriteTime Sets the date and time that the given file was last written to
The other stickler in file and directory operations is having to deal with the differences between the various
file systems on the Windows platformFAT, FAT32, and the mighty NTFS. The current file system on the
platform you are targeting your application to determines the exact format of a path. You might not always
have the pleasure of working with one file system, or even accessing a file or directory on a system other than
a version of FAT or NTFS. You thus need to come up with a flexible design to accommodate changing file
system conditions.

Some paths start with drive or volume letters, while others do not. Some file systems maintain file extensions,
and some do not. Some systems maintain a three−character extension; others let you maintain extensions of
more than three characters. The separator characters of path namespaces also differ from platform to platform.
And you probably know that various TCP/IP path elements are separated with forward slashes instead of the
backslashes of the UNC.

Paths can also contain absolute or relative location information. Absolute paths specify physical locations that
can be uniquely identified. Relative paths specify a partial location that still requires additional resolution.

File systems on the various platforms in use today are as different as humming birds are from fruit beetles. To
cater to these differences (remember we are living in the era of the Internet and distributed functionality),
.NET provides a class you can use to process path strings as platform independently as possible.

The members of the Path class are not used to physically operate on files and folders. You will use the
aforementioned file and directory classes and objects for that. But Path's members are used to verify and
modify path strings before you submit them as arguments to methods that do manipulate file systems objects.

When you use Path to verify a path string, it will throw an ArgumentException if your path string characters
do not evaluate correctly. You decide what is or is not correct. The invalid characters get defined in an
InvalidPathChars array, which gets looked at when you request verification.

Here's an example: Invalid path characters on some platforms include quote ("), less than (<), greater than (>),
pipe (|), backspace (\b), null (\0), and Unicode characters 16 through 18 and 20 through 25. You'll thus insert
these characters into the InvalidPathChars array and then use this construct to filter out bad path strings.

The Path class is also very useful for other path operations, such as enabling you to quickly and easily
perform common operations like determining whether a filename extension is part of a path, or the combining
of two strings to make one pathname. Table 15−10 lists the members of the Path class.

The following example uses several members of the Path class to work files and path names and to determine
if the paths passed to various file and directory methods are acceptable. Please note that these properties have
been extracted from a class that encapsulates the contructs of the Path class. The first example calls the

522

You might also like