Files have always been an important aspect of programming. We use files to store data, and in many cases we have to manipulate files and folders from within applications. I do not need to give examples: Just about any application that allows user input must store its data to a file (or multiple files) for […]
Read More...Using the My.Computer.FileSystem Component in Visual Basic 2008
Using the My object, you can write some text to a file via a single statement. The WriteAllText method accepts as arguments a path and the string to be written to the file (as well as a third optional argument that determines whether the text will be appended to the file or will replace the […]
Read More...Manipulating Folders & Files with the IO Namespace in Visual Basic 2008
In this section, you’ll learn how to access and manipulate files and folders with the help of the Directory and File classes of the System.IO namespace. The Directory class provides methods for manipulating folders, and the File class provides methods for manipulating files. These two objects allow you to perform just about any of the […]
Read More...The Directory Class of System.IO namespace in Visual Basic 2008
The System.IO.Directory class exposes all the members you need to manipulate folders. Because the Directory class belongs to the System.IO namespace, you must import the IO namespace into any project that might require the Directory object’s members with the following statement:
1 | Imports System.IO |
Methods The Directory object exposes methods for accessing folders and their contents, which […]
Read More...The File Class of System.IO namespace in Visual Basic 2008
The System.IO.File class exposes methods for manipulating files (copying them, moving them around, opening them, and closing them), similar to the methods of the Directory class. The names of the methods are self-descriptive, and most of them accept as an argument the path of the file on which they act. Use these methods to implement […]
Read More...DriveInfo, DirectoryInfo, and FileInfo classes – Visual Basic 2008
The IO namespace provides three objects that represent drives, folders, and files: the DriveInfo, DirectoryInfo, and FileInfo classes. These classes, in turn, expose a number of basic properties of the entities they represent. Notice that they’re instance objects, and you must create a new instance of the corresponding class by specifying the name of a […]
Read More...The Path Class in Visual Basic 2008
The Path class contains an interesting collection of methods, which you can think of as utilities. The Path class’s methods perform simple tasks such as retrieving a file’s name and extension, returning the full path description of a relative path, and so on. The Path class’s members are shared, and you must specify the path […]
Read More...The CustomExplorer Application – Visual Basic 2008
The CustomExplorer application, which demonstrates the basic properties and methods of the Directory and File classes, duplicates the functionality of Windows Explorer. Its user interface, shown in Figure 11.1, was discussed in section, “The TreeView Control.” In this chapter, you’ll see how to access the file system and populate the two controls with folder names […]
Read More...Accessing Files in Visual Basic 2008
In the first half of the chapter, you learned how to manipulate files and folders. Now we’ll discuss how to access files (write data to files and read it back). You’ve already seen the various Open methods of the File class, which return a Stream object. It’s this object that provides the methods for writing […]
Read More...The FileStream Class in Visual Basic 2008
The Stream class is an abstract one, and you can’t use it directly in your code. To prepare your application to write to a file, you must set up a FileStream object, which is the channel between your application and the file. The methods for writing and reading data are provided by the StreamReader/StreamWriter or […]
Read More...