18.01.2013 Views

Mastering Visual Basic .NET

Mastering Visual Basic .NET

Mastering Visual Basic .NET

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

change the last access time for a file is so that the specific file will be excluded from a routine that<br />

deletes old files, or to include it in a list of backup files (with an automated procedure that backs up<br />

only the files that have been changed since their last backup).<br />

GetLastWriteTime, SetLastWriteTime<br />

These two methods are equivalent to the GetCreationTime and SetCreationTime methods, but they<br />

return and set the most recent date and time the file was written to.<br />

GetLogicalDrives<br />

This method returns an array of strings, which are the names of the logical drives on the computer.<br />

The statements in Listing 13.6 print the names of all logical drives.<br />

Listing 13.6: Retrieving the Names of All Drives on the Computer<br />

Dim drives() As String<br />

drives = Directory.GetLogicalDrives<br />

Dim iDrive As Integer<br />

For iDrive = 0 To drives.GetUpperBound(0)<br />

Console.WriteLine(drives(iDrive))<br />

Next<br />

When executed, these statements will produce a list like the following:<br />

A:\<br />

C:\<br />

D:\<br />

E:\<br />

GetParent<br />

This method retrieves an object that represents the properties of a folder’s parent folder. The syntax<br />

of the GetParent method is<br />

parent = Directory.GetParent(path)<br />

The return value is a DirectoryInfo object, and it must be declared with a statement like the<br />

following:<br />

Dim parent As DirectoryInfo<br />

The name of the parent folder, for example, is parent.Name and its full name is parent.FullName.<br />

Move<br />

This method moves an entire folder to another location in the file system; its syntax is<br />

Directory.Move(source, destination)<br />

ACCESSING FOLDERS AND FILES<br />

577

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!