SlideShare a Scribd company logo
1 of 12
Microsoft® Small Basic File Input and Output Estimated time to complete this lesson: 1 hour
File Input and Output In this lesson, you will learn about: Using different properties of the File object. Using different operations of the File object.
The File Object The File object includes various operations and properties, such as: With the help of the File object in Small Basic, you can access information from a file stored on your computer. You can also read and write information from and to the file.  A computer file is a collection of data stored by your computer. Small Basic programming allows you to work with external files from your program.  CreateDirectory WriteLine AppendContents CopyFile GetFiles DeleteDirectory GetDirectories ReadContents LastError
Operations of the File Object ,[object Object],You can use the WriteLine operation to write a line of text at the specified line number in a file.  ,[object Object],With the AppendContents operation, you can add the specified text at the end of a file.  ,[object Object],Use the ReadContents operation to read the entire contents of a specified file. As you see, the File object provides many ways of working with files. Let’s learn about some operations of the File object…
Operations of the File Object Let’s write a program to gain better understanding of these operations. In this example, you specify a file path and use the WriteLineoperation to write a sentence to the file. Next, you use the AppendContents operation to add a sentence to the existing content. Finally, you use the ReadContents operation to read the entire contents of the file. output
Operations of the File Object ,[object Object],You can use the CopyFile operation to copy the specified file to a destination.  ,[object Object],With the GetFiles operation, you can get a list of all the files present in the specified directory.
Operations of the File Object Let’s write a program to better understand these operations. output In this example, you use the CopyFile operation to copy the specified source file to the specified destination. You also specify the directory path, and then use the GetFilesoperation to display the path of all files in the output window.
Operations of the File Object ,[object Object],Use the CreateDirectory operation to create the specified directory at the desired location.  ,[object Object],With the GetDirectoriesoperation, you can get the path of all the directories in the specified directory path.
Operations of the File Object Let’s see how we can apply these operations… output As you see, you first use the CreateDirectory operation to create a directory.  Next, you use the GetDirectories operation to get the path of the all the directories present in the specified location.
The LastError Property With the help of the LastError property, you can get details of the last file-operation-based error in your program. This property is quite useful when you can’t execute a file operation in your program because of some error. In this example, you use  the WriteLine operation of the File object to write text to the file at a specific line number. Next you use the LastErrorproperty of the File object to get the details of the actual error in the program, if any. output
Let’s Summarize… Congratulations! Now you know how to: Use different properties of the File object. Use different operations of the File object.
It’s Time to Apply Your Learning… Write a program by performing the following steps: ,[object Object]

More Related Content

Similar to 3.1 file input and output (20)

File Handling
File HandlingFile Handling
File Handling
 
File Handling
File HandlingFile Handling
File Handling
 
Chapter - 5.pptx
Chapter - 5.pptxChapter - 5.pptx
Chapter - 5.pptx
 
File Handling In C++
File Handling In C++File Handling In C++
File Handling In C++
 
File handling.pptx
File handling.pptxFile handling.pptx
File handling.pptx
 
UNIT 5.pptx
UNIT 5.pptxUNIT 5.pptx
UNIT 5.pptx
 
7 Data File Handling
7 Data File Handling7 Data File Handling
7 Data File Handling
 
Filehandling
FilehandlingFilehandling
Filehandling
 
ExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdfExplanationThe files into which we are writing the date area called.pdf
ExplanationThe files into which we are writing the date area called.pdf
 
Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9Filepointers1 1215104829397318-9
Filepointers1 1215104829397318-9
 
File Management and manipulation in C++ Programming
File Management and manipulation in C++ ProgrammingFile Management and manipulation in C++ Programming
File Management and manipulation in C++ Programming
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
File handling3.pdf
File handling3.pdfFile handling3.pdf
File handling3.pdf
 
File handling4.pdf
File handling4.pdfFile handling4.pdf
File handling4.pdf
 
File handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptxFile handling in C hhsjsjshsjjsjsjs.pptx
File handling in C hhsjsjshsjjsjsjs.pptx
 
C- language Lecture 8
C- language Lecture 8C- language Lecture 8
C- language Lecture 8
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
Python-FileHandling.pptx
Python-FileHandling.pptxPython-FileHandling.pptx
Python-FileHandling.pptx
 
VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5VIT351 Software Development VI Unit5
VIT351 Software Development VI Unit5
 

More from allenbailey

5.1 sharing code
5.1   sharing code5.1   sharing code
5.1 sharing codeallenbailey
 
4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced gamesallenbailey
 
4.3 collision detection
4.3   collision detection4.3   collision detection
4.3 collision detectionallenbailey
 
4.2 responding to events
4.2   responding to events4.2   responding to events
4.2 responding to eventsallenbailey
 
4.1 playing with shapes
4.1   playing with shapes4.1   playing with shapes
4.1 playing with shapesallenbailey
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls objectallenbailey
 
3.4 events and interactivity
3.4   events and interactivity3.4   events and interactivity
3.4 events and interactivityallenbailey
 
3.3 the math object
3.3   the math object3.3   the math object
3.3 the math objectallenbailey
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arraysallenbailey
 
2.6 flickr, image list, and network objects
2.6   flickr, image list, and network objects2.6   flickr, image list, and network objects
2.6 flickr, image list, and network objectsallenbailey
 
2.5 clock, desktop, and dictionary objects
2.5   clock, desktop, and dictionary objects2.5   clock, desktop, and dictionary objects
2.5 clock, desktop, and dictionary objectsallenbailey
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapesallenbailey
 
2.2 turtle graphics
2.2   turtle graphics2.2   turtle graphics
2.2 turtle graphicsallenbailey
 
2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics windowallenbailey
 

More from allenbailey (14)

5.1 sharing code
5.1   sharing code5.1   sharing code
5.1 sharing code
 
4.4 advanced games
4.4   advanced games4.4   advanced games
4.4 advanced games
 
4.3 collision detection
4.3   collision detection4.3   collision detection
4.3 collision detection
 
4.2 responding to events
4.2   responding to events4.2   responding to events
4.2 responding to events
 
4.1 playing with shapes
4.1   playing with shapes4.1   playing with shapes
4.1 playing with shapes
 
3.5 the controls object
3.5   the controls object3.5   the controls object
3.5 the controls object
 
3.4 events and interactivity
3.4   events and interactivity3.4   events and interactivity
3.4 events and interactivity
 
3.3 the math object
3.3   the math object3.3   the math object
3.3 the math object
 
3.2 stacks and arrays
3.2   stacks and arrays3.2   stacks and arrays
3.2 stacks and arrays
 
2.6 flickr, image list, and network objects
2.6   flickr, image list, and network objects2.6   flickr, image list, and network objects
2.6 flickr, image list, and network objects
 
2.5 clock, desktop, and dictionary objects
2.5   clock, desktop, and dictionary objects2.5   clock, desktop, and dictionary objects
2.5 clock, desktop, and dictionary objects
 
2.3 exploring shapes
2.3   exploring shapes2.3   exploring shapes
2.3 exploring shapes
 
2.2 turtle graphics
2.2   turtle graphics2.2   turtle graphics
2.2 turtle graphics
 
2.1 graphics window
2.1   graphics window2.1   graphics window
2.1 graphics window
 

Recently uploaded

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 

Recently uploaded (20)

Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 

3.1 file input and output

  • 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 about: Using different properties of the File object. Using different operations of the File object.
  • 3. The File Object The File object includes various operations and properties, such as: With the help of the File object in Small Basic, you can access information from a file stored on your computer. You can also read and write information from and to the file. A computer file is a collection of data stored by your computer. Small Basic programming allows you to work with external files from your program. CreateDirectory WriteLine AppendContents CopyFile GetFiles DeleteDirectory GetDirectories ReadContents LastError
  • 4.
  • 5. Operations of the File Object Let’s write a program to gain better understanding of these operations. In this example, you specify a file path and use the WriteLineoperation to write a sentence to the file. Next, you use the AppendContents operation to add a sentence to the existing content. Finally, you use the ReadContents operation to read the entire contents of the file. output
  • 6.
  • 7. Operations of the File Object Let’s write a program to better understand these operations. output In this example, you use the CopyFile operation to copy the specified source file to the specified destination. You also specify the directory path, and then use the GetFilesoperation to display the path of all files in the output window.
  • 8.
  • 9. Operations of the File Object Let’s see how we can apply these operations… output As you see, you first use the CreateDirectory operation to create a directory. Next, you use the GetDirectories operation to get the path of the all the directories present in the specified location.
  • 10. The LastError Property With the help of the LastError property, you can get details of the last file-operation-based error in your program. This property is quite useful when you can’t execute a file operation in your program because of some error. In this example, you use the WriteLine operation of the File object to write text to the file at a specific line number. Next you use the LastErrorproperty of the File object to get the details of the actual error in the program, if any. output
  • 11. Let’s Summarize… Congratulations! Now you know how to: Use different properties of the File object. Use different operations of the File object.
  • 12.
  • 13. Download a file from the network and copy it to the created directory.
  • 14. Display the contents of the downloaded file in the text window.
  • 15. Accept additional content from the user and add that content to the file.
  • 16. Display the final content from the file in the text window.

Editor's Notes

  1. Using the File object, you can also save and open settings across various sessions of your program.
  2. If the WriteLine operation is successful, it displays “SUCCESS” in the output window; otherwise, it displays “FAILED”. It will overwrite the previously written content on the specified line. Likewise, if the AppendContents operation is successful, it displays “SUCCESS” in the output window; it displays “FAILED” if unsuccessful. The ReadContents operation is faster when the size of the file is less than 1 MB. The operation slows down as the size of the file increases—especially for files larger than 10 MB. It displays the entire contents of the specified file on the output window.Code:Writeline:File.WriteLine("C:Small Basic.txt", 1, "Hello")AppendContents:File.AppendContents("C:Small Basic.txt","Take Care")ReadContents:File.ReadContents("C:Small Basic.txt”)
  3. Code:FilePath = "C: empTempSubdirectorymy.txt"TextWindow.WriteLine("Write Content = " + File.WriteLine(FilePath, 1, "Shakespeare was a great writer."))TextWindow.WriteLine("Append Content = " + File.AppendContents(FilePath, "He wrote many plays."))TextWindow.WriteLine("Read Content = " + File.WriteLine(FilePath))
  4. Code:FilePath = "C: empTempSubdirectmy.txt"TextWindow.WriteLine("Write Line Operation: " + File.WriteLine(FilePath, 1, "How are you?"))If File.LastError = "" ThenTextWindow.WriteLine("Operation Successful")ElseTextWindow.WriteLine(File.LastError)EndIf
  5. Please Note: The file must exist at the specified network path for the solution to work.Solution:TextWindow.Write("Enter the name of the new directory: ")DirectoryName = TextWindow.Read()File.CreateDirectory(DirectoryName)filepath = "\mum-9785smShareFileIO.txt"downloadpath = Network.DownloadFile(filepath) If File.CopyFile(downloadpath, DirectoryName) = "SUCCESS" Then TextWindow.WriteLine("File has been downloaded from the network and copied to: " + DirectoryName)  files = File.GetFiles(DirectoryName) TextWindow.WriteLine("This is the content in the file: ") TextWindow.WriteLine(File.ReadContents(files[1])) TextWindow.Write("Enter data to be added in the file:")AppendedData = TextWindow.Read()File.AppendContents(files[1]," " + AppendedData)TextWindow.WriteLine("File content after adding data is as follows: ") TextWindow.WriteLine(File.ReadContents(files[1])) EndIf