I’m trying to read a collection of yaml files in a directory without hardcoding it. VirtualFile.readFile(bool) is throwing an assertion error and I am not sure how I am doing it wrong.
vfs = VirtualFileSystem.getGlobalPtr()
textFileList = vfs.scanDirectory('text')
i = 0
while i < textFileList.size():
print "Reading " + str(textFileList[i])
content = textFileList[i].readFile(True)
i += 1
But the file being read is a regular file (its in the output line). I’ve also added an isRegularFile() check too with the same issue
while i < textFileList.size():
print "Reading " + str(textFileList[i])
if textFileList[i].isRegularFile():
content = textFileList[i].readFile(True)
i += 1
That would be a good idea, but at this point the only Filename I am using is for the “text” directory. vfs.scanDirectory returns a VirtualFileList, which returns VirtualFiles, none of which have a setText function.
textDirectoryName = Filename('text') # This is a directory with *.yaml files
textFileList = vfs.scanDirectory(textDirectoryName)
i = 0
while i < textFileList.size():
print "Reading " + str(textFileList[i]) # Shows the full and correct path to the yaml file
if textFileList[i].isRegularFile():
content = textFileList[i].readFile(True)
i += 1