Small Basic #10: File Input and Output

As demonstrated in the following code, you can use the Microsoft Small Basic File class to create file directories, access directories’ files, and copy files from one file directory to another. You can also read from files and write to files.

‘ This code assumes that a directory named C:\Temp\ already exists.
TextWindow.WriteLine(“Subdirectory created: ” + File.CreateDirectory(“C:\Temp\TempSubdirectory\”))
subdirectories = File.GetDirectories(“C:\Temp”)

If Array.GetItemCount(subdirectories) = 1 Then
TextWindow.WriteLine(“C:\Temp has 1 subdirectory.”)
TextWindow.WriteLine(“C:\Temp has ” + Array.GetItemCount(subdirectories) + ” subdirectories.”)

For i = 1 To Array.GetItemCount(subdirectories)
TextWindow.WriteLine(“subdirectories[” + i + “] = ” + subdirectories[i])
files = File.GetFiles(“C:\Temp\” + subdirectories[i])
For j = 1 To Array.GetItemCount(files)
TextWindow.WriteLine(” files[” + i + “] = ” + files[i])

TextWindow.WriteLine(“This program’s file path is ” + File.GetSettingsFilePath())

filePath = File.GetTemporaryFilePath()
TextWindow.WriteLine(“A temporary file has been created at: ” + filePath + “.”)
TextWindow.WriteLine(“Write to file: ” + File.WriteContents(filePath, “Hello, World!”))
TextWindow.WriteLine(“Write line to file: ” + File.WriteLine(filePath, 15, “Hello Again, World!”))
TextWindow.WriteLine(“Insert line in file: ” + File.InsertLine(filePath, 20, “Hello Once Again, World!”))
TextWindow.WriteLine(“Append to file: ” + File.AppendContents(filePath, “Hello For the Last Time, World!”))
TextWindow.WriteLine(“File contains: ” + File.ReadContents(filePath))
TextWindow.WriteLine(“Copy file: ” + File.CopyFile(filePath, “C:\Temp\TempSubdirectory\”))

If File.LastError = “” Then
TextWindow.WriteLine(“The last error was: ” + File.LastError)

Comments (17)

  1. MaStA-hAcKeR667 says:

    Decent code …………….. for an amateur

    Why is the i x derivitive controlling the variable. Everyone knows that an inverse dilema causes a response by the stem TO the leaf. It child's play

  2. M4STER-C0mputer$$$$$$$$$$$$$$$$$ says:

    m8 dis iz basic ahah are u a special needz bent guy lmaoooooooooooooooooooooooooooooooooooooooooooooooo000000000000000000000000000000000000000000000000000000000000000000

  3. trollking says:

    OMG shut the f*ck up you silly c*unt

  4. M4STER-C0mputer$$$$$$$$$$$$$$$$$ says:

    trollking & MaStA-hAcKeR667

    want a slap m8s im in the army

  5. MaStA-hAcKeR667 says:

    M4STER-C0mputer$$$$$$$$$$$$$$$$$ can suck my d*ck

    I will bend u over and fluctuate your servers

  6. munkhbat says:

    Program that calculates the sum of the two numbers SMALLBASIC please write in the language.The input data file to read and write the results file.

  7. Your mother says:

    So is this what you do in your spare time?

  8. The Master Troll says:

    I fluctuate my servers on the daily

  9. ( ͡° ͜ʖ ͡°)Come Hither( ͡° ͜ʖ ͡°) says:

    ( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°)( ͡° ͜ʖ ͡°)

  10. And his name is says:

    JOHN CENA. du doo du dooooooooooo00ooo

  11. why why says:

    the f*** you lyinnnnn

    oh my godddddddddddddddd

    stop f***ing lyinnnnnnn

  12. M8 says:

    I swear on me mums lyfe I cant figure oot how 2 reed and rite to atext fyle :(((((

  13. Sugar.Honey.Ice.Tea says:

    A N D  H I S  N A M E  I S  J O H N  C E N A. duDUUuduu dooo000oooo

  14. I'm watching you says:

    …. That's exactly what the undertaker told J O H N  C E N A *yabadooo… du doo du doo00ooo*

  15. matey says:

    I well actually rekt  ya mayte, I can not fluctuate my servers :(( I hev to get me mum to halp me to do it, why do I even try at lfe sense im sooch a fayle :???

  16. Count Püd says:

    I'm loving the fact that this code was meant to help people and all you wankers are doing is arguing over petty bullshit

  17. User Ed says:

    Hello! If anyone has any questions, please ask in the Small Basic forum:…/threads