5.3. Copy, Move, or Delete a File or a Directory

Problem

You need to copy, move, or delete a file or directory.

Solution

You have two main options for manipulating files and directories. One option is to create a System. IO.FileInfo object for a file or a System.IO.DirectoryInfo object for a directory, supplying the path in the constructor. You can then use the object's methods to copy, move, and delete the file or directory. Alternatively, you can use the My.Computer.FileSystem class and its Shared methods.

How It Works

The FileInfo, DirectoryInfo, and My.Computer.FileSystem classes include a host of valuable methods for manipulating files and directories. Table 5-3 shows methods for the FileInfo class, Table 5-4 shows methods for the DirectoryInfo ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach 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.