Quantcast
Channel: Small Basic
Viewing all articles
Browse latest Browse all 669

Small Basic - File Tips

$
0
0

Today I will introduce some tips about File object in Small Basic.

File.LastError

Have you ever used File.LastError?  Following program is a sample using File.LastError.  File.LastError property contains file error message from Windows system.  Following is a sample code.

GetPath()
While path <> ""
  TextWindow.WriteLine("[" + path + "]")
  files = File.GetFiles(path)
  If files = "FAILED" Then
    TextWindow.WriteLine("File.GetFiles: FAILED")
    TextWindow.WriteLine("File.LastError: " + File.LastError)
    TextWindow.WriteLine("")
  Else
    n = Array.GetItemCount(files)
    For i = 1 To n
      TextWindow.WriteLine(files[i])
    EndFor
    TextWindow.WriteLine("")
  EndIf
  GetPath()
EndWhile
Sub GetPath
  ' return path
  TextWindow.Write("Path? ")
  path = TextWindow.Read()
EndSub

Following list is a sample output of this program.  File.LastError message is written in local language of your system.

Path? notexist
[notexist]
File.GetFiles: FAILED
File.LastError: Directory Path does not exist.

Path?

Dot in Path

Path names given in File operations should be full path names.  But "." and ".." are allowed as full path names.  "." means a current directory.  ".." means a parent directory.

Path? ..\..
[..\..]
..\..\bootmgr
..\..\BOOTNXT
..\..\pagefile.sys
..\..\swapfile.sys

Path?

Slash in Path

A path name may contain back slash "\".  But slash "/" also can be used instead of back slash.

Path? /Program Files (x86)/Microsoft/Small Basic/lib
[/Program Files (x86)/Microsoft/Small Basic/lib]
/Program Files (x86)/Microsoft/Small Basic/lib\LitDev.De.xml
/Program Files (x86)/Microsoft/Small Basic/lib\LitDev.dll
/Program Files (x86)/Microsoft/Small Basic/lib\LitDev.xml
/Program Files (x86)/Microsoft/Small Basic/lib\Microsoft.Kinect.dll
/Program Files (x86)/Microsoft/Small Basic/lib\Microsoft.Kinect.Face.dll
/Program Files (x86)/Microsoft/Small Basic/lib\Microsoft.Kinect.SmallBasic.dll
/Program Files (x86)/Microsoft/Small Basic/lib\Microsoft.Kinect.SmallBasic.XML
/Program Files (x86)/Microsoft/Small Basic/lib\Microsoft.Kinect.Wpf.Controls.dll

Path?

Viewing all articles
Browse latest Browse all 669

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>