To do this step they would have to do the following:. First, make the directories:. Next, they would have to move the appropriate set of files from the root to the proper directory. For the last step, they were instructed as follows:. Place copies of the. EXE and. INI files there. TXT and. WRI files there. To do this, they would have to issue the following commands:.
The student would then turn their disk into the instructor, who would check to make sure that all the proper directories were created and that the files were in the right place.
As a follow-up exercise, students were given the disks back and asked to restore the disk back to its original state — i. WRI files from their respective top-level directories back to the root. At this point, the exercise would be complete and the disk could be turned back into the instructor. To do the sample project that implements these actions, you need a "clean" empty floppy disk.
The sample files shown above the. INI, etc. The project download below, when unzipped, contains a folder called "FileSysDemoFiles", from where the files can be copied. As an alternative, you can simply make empty files using Notepad and save them with those names, and then copy them to a floppy. For the purpose of this exercise, the content of these files do not matter; for example, the "exe" and "com" files need not be valid executables.
The sample project is a modified "Try It" program. The "Clear" button was changed to "Reset" the caption was changed "Reset" and the name was changed to "cmdReset". The "Try It" button implements the first part of the exercise makes the subdirectories and moves and copies the files to their proper locations.
The "Reset" button implements the second part of the exercise puts all files back to the root directory and removes all of the subdirectories. That way, it is available to all Subs and Functions in the form. The "New" keyword is used, making the various methods and properties of the FSO available without using a separate "Set" statement to instantiate it.
The code is heavily commented to aid in the understanding of what the code is doing. You will notice that two statements, "DoEvents" and "Refresh" are used throughout the procedure. The DoEvents statement "yields execution so that the operating system can process other events". Refresh" or "frmTest. The Refresh method forces the form to repaint itself. The Refresh method was used to ensure that each "Print" message is displayed at the desired time during processor-intensive operations, the form does not always automatically repaint itself when we want it to.
Print "Top-level directories have been made. The Sub takes four arguments: 1 source path,. The Sub is called six. Print "Files have been moved from root to top-level directories. Print "Done. Dim strCurrentFile As String. Dim strPattern As String. Dim strSourceFile As String. Dim strTargetFile As String. In the previous. If a "move" was specified, the files that were copied had to be deleted.
There is no specific statement to move files in the set of. MoveFile strPattern, pstrTargetPath. CopyFile strPattern, pstrTargetPath. The Sub takes two arguments: 1 the individual. An important difference. Download the VB project code for the example above here. The second sample program combines the functionality of two sample program presented in the previous topics on reading and writing a fixed-width sequential file.
Upon clicking the "Try It" button, the program first displays the records currently in the file. The user is then prompted to add records an InputBox is used to prompt for each field, starting with the employee name :. The user enters the name, followed by the other fields with each successive prompt:.
Once the fields that make up a record have been entered, that record is written to the file and is displayed on the form, and the next set of prompts begins:. When the user is done entering records, they would click "Cancel" on the InputBox when prompted for the name, and the prompting will stop.
The resulting form will show all the records that were initially read, as well as all the records that were just entered:. Dim strBackSlash As String. Dim strEmpRecord As String. Dim strEmpName As String.
Dim intDeptNbr As Integer. Dim strJobTitle As String. Dim dtmHireDate As Date. Dim sngHrlyRate As Single. Print "The following records were read from the text file:".
Tab 71 ; "". The second argument of the OpenTextFile method. Do Until objTextFile. Print "The following records were written to the text file:". The FileSystemObject is used to gain access to a computer's file system.
It can create new files and access existing ones. Returns a Drives collection consisting of all the Drive objects on a computer. BuildPath path, name. This method is used to append a name onto an existing path.
Syntax: object. CopyFile source, destination [,overwrite]. This method allows us to copy one or more files from one location the source to another destination. CopyFolder source, destination [, overwrite]. Copies one or more folders and all contents, including files and subfolders, from one location to another.
CreateFolder foldername. This method allows us to create a folder with the specified foldername. Previous Page. Next Page. Useful Video Courses. More Detail. Previous Page Print Page. Save Close. Drive Drive is an Object. Drives Drives is a Collection. Any additional feedback? In this article. Creates a text file and returns a TextStream object that can be used to read from, or write to the file.
Returns the complete path from the root of the drive for the specified path. Returns a Drive object corresponding to the drive in a specified path. Returns the file extension name for the last component in a specified path.
0コメント