[Gambas-user] chat.openai.com and gambas3

Charlie Reinl Karl.Reinl at Fen-Net.de
Tue Mar 21 23:11:27 CET 2023


I asked	-> Q:

fill an array with the files of a directory with gambas3

This is the answer from chat.openai.com -> A:

To fill an array with the files of a directory in Gambas 3, you can use
the "Dir()" function. This function returns a list of all files and
directories in the specified path.

Here is an example code that fills an array with the files in a
directory:

[code]
vbnet

Public Sub FillArrayWithFiles(directory As String)
  Dim files[] As String
  Dim filename As String
  
  files = Dir(directory & "/*")
  
  For Each filename In files
    If Not Is_Directory(directory & "/" & filename) Then
      ' add filename to array
      Array.Append(files, filename)
    Endif
  Next
End
[/code]

This code creates an empty array "files[]" and fills it with all file
names in the specified directory. If the path does not exist or is not
a directory, an empty array is returned.

Note: Note that "Is_Directory()" is another Gambas function that checks
whether the path is a directory. You can avoid using this function by
using "Dir()" with the "DIRECTORY" option, which only returns
directories.
<<
ChatGPT Mar 14 Version. Free Research Preview. Our goal is to make AI
systems more natural and safe to interact with. Your feedback will help
us improve.
>>

Not usable!
-- 
Amicalement
Charlie



More information about the User mailing list