O'Reilly logo

Visual Basic 2005 Cookbook by Tim Patrick, John Clark Craig

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. Files and File Systems

Introduction

One of the core features of any operating system is how it interacts with a file system. MS-DOS, the predecessor of Microsoft Windows, even alludes to this importance in its name: the “D” in “MS-DOS” stands for “Disk.” With this stress on file systems and files, it’s only natural that the .NET Framework includes significant support for manipulating directories, files, and the contents of files.

The recipes in this chapter introduce many of the file-management and -manipulation features found in .NET and Visual Basic. For the Visual Basic programmer, much of the focus is on the My.Computer.FileSystem object, which provides a virtual cornucopia of file-management features.

The Windows file system includes support for security and access limitations, imposed either by the administrator or by standard users. Even if a recipe in this chapter says, “You can do such and such,” it may not be true for users who have had file-system limits placed on them or their programs. This is especially true of Click-Once-deployed applications, which can be run in a type of “sandbox” that places harsh limits on file access.

12.1. Enumerating Drives

Problem

You need access to the list of drives available on the local workstation.

Solution

Sample code folder: Chapter 12\EnumerateDrives

Use the My.Computer.FileSystem.Drives collection to enumerate through the logical drives.

Discussion

If you have a form (Form1) with a ListBox control (ListBox1), the following code ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required