folder.length returns 0

Hi All.

I am trying to re-teach myself Xojo (having started in RealBasic a long time ago), and I’m working through the introduction to Xojo programming.

In the folder example, they have this line:

FileBox.AddRow(“Size: " + Str(myFolder.Length) + " bytes”)

According to the online documentation, the line is correct, but I always get a 0 returned as if it has no length (size) even though there are files in it. I have tried different folders some with only a couple of text documents in it, some with pictures, but it is always 0.

Any idea as to what I am doing wrong?

Regards

This is normal.

If you take a look at the the document entry for FolderItem.Length, near the top there’s a line “For directories, the size will be zero.”

I don’t know why this is put into the demo selecting folders without an explanation that 0 will be returned as it will always return 0 as the length is related to a selected file.

Welcome back to Xojo :slight_smile:

Use Count if you want to know the number of items in a folder:

http://documentation.xojo.com/api/files/folderitem.html.Count

Thanks for that. As I said I was working through the Introduction to Xojo book, and this was part of their code.
Hmmm… (grin)

Regards

Version 3 ?

This code:

[code]Dim myFolder As FolderItem
Dim d As SelectFolderDialog
d = New SelectFolderDialog
myFolder = d.ShowModal
If myFolder <> Nil Then

FileBox.AddRow("Name: " + myFolder.Name)
FileBox.AddRow(“Size: " + ¬
Str(myFolder.Length) + " bytes”)
FileBox.AddRow("Items: " + Str(myFolder.Count))
FileBox.AddRow("Parent: " ¬

  • myFolder.Parent.Name)
    End If[/code]

Edit:

Warning: at the end of the book (pdf), you may read:
This work is copyright © 2012-2016 by Xojo, Inc.

And today’s date is 2019-04-08. Many changes have been done since three years ago.