CREATE TEXT FILE - pi console

Am using Pi4 and I would like to create a text file in “/home/ir4”

Using below code i can create a folder but i cannot create text file

Dim f as FolderItem = GetfolderItem("/home/ir4/")
Dim today As new date
If f.Exists = False Then
f = f.Child(Str(today.Year)+Str(format(today.Month,“00”))+Str(format(today.Day,“00”)))
If f.Exists = False Then
If f = Nil Then
f = GetSaveFolderItem(".txt", “LOG_”+Str(format(today.Day,“00”))+Str(format(today.Month,“00”))+Str(format(today.Year,“00”))+".txt")

GetSaveFolderItem - This item doesn’t exit error appear.
Help me out how to create a text file in Pi console application.

GetSaveFolderItem is not avaliable for console, there is no GUI to display file/folder choices. This may work:

f = GetFolderItem(f.NativePath + “LOG_”+Str(Format(today.Day,“00”))+Str(Format(today.Month,“00”))+Str(Format(today.Year,“00”))+".txt")

Create a text file like so:


Var file As New FolderItem("path/to/a/file.txt", FolderItem.PathModes.Shell)
Var stream As TextOutputStream = TextOutputStream.Create(file)

stream.writeLine "A line of text"
stream.writeLine "Second line of text"

stream.close // <-- writes data to disk

Catch e As IOException
stdout.writeline "Oops we got an error here: "+e.Message
End Try

Not tested but that’s the concept.

Instead of GetSaveFolderItem, simply use

f = f.Child(“LOG_”+Str(format(today.Day,“00”))+Str(format(today.Month,“00”))+Str(format(today.Year,“00”))+".txt")