所以我在网上找到了这个代码(通常我会做C#,但我正在尝试向我的一个朋友教小基础)基本上是在读取一个文件:
TextWindow.Write("Enter the name of the new directory: ")
DirectoryName = TextWindow.Read()
files = File.GetFiles(DirectoryName)
TextWindow.WriteLine("This is the content in the file: ")
TextWindow.WriteLine(File.ReadContents(files[1]))
我明白这一切的作用,但为什么需要files[1]
而不只是files
?
删除索引[1]
只会使该行不起作用,程序仍会编译等等。
SB没有调试器,在线资源也不是很好。
答案 0 :(得分:0)
根据API文档,File.GetFiles
返回一个数组:
如果操作成功,则将文件作为数组返回。否则,它将返回“FAILED”。
您指定索引,因为它返回一个数组,而File.ReadContents
需要一个实例。
在此处查看API:http://smallbasic.com/doc/?id=6