|
An Introduction to Programming Using Visual Basic 2005 Authors: Schneider D.I. Published year: 2006 Pages: 12/164 |
1.3. Files and FoldersModern computers have a hard disk, a diskette drive, and a CD (or DVD) drive. The hard disk is permanently housed inside the computer. You can read information from all three drives , but can write information easily only to the hard disk and to diskettes. We use the word disk to refer to either the hard disk, a diskette, a CD, or DVD. Each drive is identified by a letter. Normally, the hard drive is identified by C, the diskette drive by A, and the CD (or DVD) drive by D or E. Disk management is handled by Windows. Disks hold not only programs, but also collections of data stored in files. The term file refers to either a program file, a text file, or some other kind of data file. We created a text file in Section 1.2. Each file has a name consisting of a base name followed by an optional extension consisting of a period and one or more characters . The term filename refers to the combination of the base name, the period, and the extension. A filename can contain up to 215 characters, typically consisting of letters , digits, spaces, periods, and other assorted characters. (The only characters that cannot be used in filenames are \, /, :, *, ?, <, >,", and ) Extensions are normally used to identify the type of file. For example, spreadsheets created with Excel have the extension xls (eXceL Spreadsheet), documents created with Word have the extension doc (DOCument), and files created with Notepad have the extension txt (TeXT document). Some examples of filenames are "Annual Sales.xls," "Letter to Mom.doc," and "Phone.txt". Neither Windows nor Visual Basic distinguishes between uppercase and lowercase letters in folder and filenames. For instance, the names COSTS02.TXT, Costs02.Txt, and costs02.txt are equivalent. We use uppercase letters in this book for filenames. Because a disk is capable of holding thousands of files, locating a specific file can be quite time consuming. Therefore, related files are grouped into collections called folders . For instance, one folder might hold all your Visual Basic programs, and another the documents created with your word processor. Think of a disk as a large folder, called the root folder , that contains several smaller folders, each with its own name. (The naming of folders follows the same rules as the naming of files.) Each of these smaller folders can contain yet other named folders. Any folder contained inside another folder is said to be a subfolder of that folder. Each folder is identified by listing its name preceded by the names of the successively larger folders that contain it, with each folder name preceded by a backslash. Such a sequence is called a path . For instance, the path \Sales\NY02\July identifies the folder July, contained in the folder NY02, which in turn is contained in the folder Sales. Think of a file, along with its name, as written on a slip of paper that can be placed into either the root folder or one of the smaller folders. The combination of a drive letter followed by a colon , a path, and a filename is called a filespec , an abbreviation of "file specification." Some examples of filespecs are C:\VB01\VB.EXE and A:\Personal\INCOME02.TXT. In early operating systems such as MS-DOS, folders were called directories . Many Visual Basic objects and commands still refer to folders as directories. The terms "root folder" and "path" are a reference to the "tree" metaphor commonly used to describe a computer's disk. In this metaphor, the large folder at the lowest level of the disk is called the "root" folder. The smaller folders contained in the root folder can be thought of as "branches" that emanate from the root. Each branch may have smaller branches, which in turn may have their own smaller branches, and so on. Finally, a file in one of these folders can be thought of as a leaf on a branch. The leaf is reached by starting at the root and following a "path" through the branches. A program called Windows Explorer helps you view, organize, and manage the folders and files on your disks. We will learn how to use Windows Explorer to create, rename, copy, move, and delete folders and files. Using Windows ExplorerTo invoke Windows Explorer, click the Windows Start button, click on Run, type in the word "Explorer", and click on the OK button. The appearance of the Explorer window depends on the version of Windows being used and the values of certain settings. Figure 1.4 (on the next page) shows a possible Explorer window for Windows XP. The Folders pane on the left side of the window contains a folder tree with the My Documents folder highlighted. (Only one folder at a time can be highlighted. The icon for a highlighted folder appears to be physically open , and its name appears in the title bar at the top of the Explorer window.) The contents of the highlighted folder are displayed in the right pane of the Explorer window. In Figure 1.4, the highlighted folder contains six subfolders and two files. To highlight a different folder, just click on it with the left mouse button. Figure 1.4. An Explorer window for Windows XP(This item is displayed on page 14 in the print version)
In the Folders pane, you can click on a plus box to expand the folder tree so that it reveals the subfolders of the folder next to the plus box. You click on a minus box to reverse the process. This process allows you to locate any file. In Figure 1.4, the folders and files in the right pane are displayed in the so-called Details view . This view is invoked by pressing Alt/V/D. Also, in Figure 1.4, the extensions of the filenames are shown. By default, Windows shows only the base names of files. The following steps get it to also display the extensions:
To create a new folder :
To rename a folder or file:
To delete a folder or file:
Or
To copy a folder or file:
To move a folder or file:
You also can carry out some of the preceding operations by "drag and drop." For details, see the Help Topics accessed through the Windows Explorer Help menu. For instance, you can delete a folder or file by dragging it to the Recycle Bin and releasing the left mouse button. Using the Open and Save As Dialog BoxesIn Section 1.2, we used the Open and Save As dialog boxes by just typing in the filespec for the desired file. These dialog boxes provide many features that assist with the locating of folders and files. Figure 1.5 shows an Open dialog box obtained from Windows XP. In the Save As dialog box, "Look in:" is replaced with "Save in:", and "Files of type:" is replaced with "Save as type:". Figure 1.5. An Open dialog box from Windows XP.
You can begin the search by clicking on one of the icons in the Places bar. In Figure 1.5, the My Computer icon was pressed. The following steps would be used to locate the file with filespec "C:\VB Programs-5-3\bin\Debug\PAYROLL.TXT":
The Save As dialog box operates in a similar way. However, after the desired folder is displayed in the "Save in:" box at the top of the dialog box, you would type the base name of the file into the "File name:" box. Practice Problems 1.3
Exercises 1.3
From Windows Explorer, highlight a folder on your computer that contains many files, and then press Alt/V/D to select the Details option from the View menu. In Exercises 9-12, give the effect of clicking on the specified column head in the right-hand pane.
In Exercises 15 and 16, carry out the stated tasks .
Solutions to Practice Problems 1.3
|
|
An Introduction to Programming Using Visual Basic 2005 Authors: Schneider D.I. Published year: 2006 Pages: 12/164 |