Small Basic Sample: Directories
Code
' Sample Code - Operations and a Property of Directories
' for local directories
path = Program.Directory
fname = "temp" + Math.GetRandomNumber(999999)
err = File.CreateDirectory(path + "\" + fname) ' create a directory
If err = "FAILED" Then
ShowError()
Program.End()
EndIf
ShowDir()
err = File.DeleteDirectory(path + "\" + fname) ' delete the directory
If err = "FAILED" Then
ShowError()
Program.End()
EndIf
ShowDir()
Sub ShowDir
TextWindow.WriteLine("[" + path + "]")
dirs = File.GetDirectories(path) ' get directories
n = Array.GetItemCount(dirs)
For i = 1 To n
TextWindow.WriteLine(dirs[i])
EndFor
EndSub
Sub ShowError
TextWindow.ForegroundColor = "Red"
TextWindow.Write("Error: ")
TextWindow.WriteLine(File.LastError)
TextWindow.ForegroundColor = "Gray"
TextWindow.Pause()
EndSub
See Also