Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microsoft® Small Basic File Input and Output Estimated time to complete this lesson: 1 hour.

Similar presentations


Presentation on theme: "Microsoft® Small Basic File Input and Output Estimated time to complete this lesson: 1 hour."— Presentation transcript:

1 Microsoft® Small Basic File Input and Output Estimated time to complete this lesson: 1 hour

2 File Input and Output In this lesson, you will learn how to: Use different properties of the File object.Use different operations of the File object.

3 The File Object The File object includes the following operations and properties: A computer file is a collection of data that your computer stores. In Small Basic, you can work with external files from your program. By using the File object in Small Basic, you can access information from a file that is stored on your computer. You can also read and write information from and to the file. CreateDirectoryWriteLine AppendContentsCopyFile GetFilesDeleteDirectory GetDirectories ReadContents LastError

4 Operations of the File Object As you see, you can work with files in many ways by using the File object. Let’s learn about some operations of the File object…  WriteLine You can write a line of text at a line number that you specify in a file by using the WriteLine operation.  AppendContents You can add text that you specify at the end of a file by using the AppendContents operation.  ReadContents You can read the entire contents of a file by using the ReadContents operation.

5 Operations of the File Object Let’s write a program to gain better understanding of these operations. In this example, you specify the path of a file and write a sentence to it by using the WriteLine operation. Next, you add a sentence to the existing content by using the AppendContents operation. Finally, you read the entire contents of the file by using the ReadContents operation.

6 Operations of the File Object  CopyFile You can copy the specified file to a destination by using the CopyFile operation.  GetFiles You can get a list of all the files in a directory that you specify by using the GetFiles operation.

7 Operations of the File Object Let’s write a program to better understand these operations. In this example, you copy the specified source file to the specified destination by using the CopyFile operation. You also specify the directory path, and you then display the paths of all files in the output window by using the GetFiles operation.

8 Operations of the File Object  CreateDirectory By using this operation, you can create a directory with a name that you specify at a location that you specify.  GetDirectories By using this operation, you can get the paths of all the directories in the directory path that you specify.

9 Operations of the File Object Let’s see how we can apply these operations… First, you create a directory by using the CreateDirectory operation. Next, you get the path of all the directories in the location that you specify by using the GetDirectories operation.

10 The LastError Property By using the LastError property, you can get details about the most recent file-operation error that occurred in your program. This property is quite useful when an error prevents your program from performing a file operation. In this example, you write text to a file at a specific line number that you specify by using the WriteLine operation of the File object. Next you get the details of the actual error in the program, if any, by using the LastError property of the File object.

11 Let’s Summarize… Congratulations! Now you know how to: Use different properties of the File object. Use different operations of the File object. Use different properties of the File object. Use different operations of the File object.

12 Show What You Know Write a program that performs the following steps:  Requests a suitable name for a directory from the user, and creates a directory of that name.  Downloads a file from the network, and copies it to the new directory.  Displays the contents of the downloaded file in the text window.  Accepts additional content from the user, and adds it to the file.  Displays the final content from the file in the text window.


Download ppt "Microsoft® Small Basic File Input and Output Estimated time to complete this lesson: 1 hour."

Similar presentations


Ads by Google