# Spot the bug(s)

**URL:** <https://ifnotnil.com/t/spot-the-bug-s/1490>\
**Category:** Other\
**Created:** [18 January 2021 03:50 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490 "2021-01-18T03:50:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![npalardy](https://ifnotnil.com/user_avatar/ifnotnil.com/npalardy/32/10_2.png) [@npalardy](https://ifnotnil.com/u/npalardy)\
**Post date:** [18 January 2021 03:50 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/1 "2021-01-18T03:50:23Z")

</div>

This code is supposed to find all files that have a .txt extension in a dir

```auto
For Each f As FolderItem In dataFolder.Children
  If f.Name.Right(3) = "txt" Then
    MainListBox.AddRow(f.NativePath)
  End If
Next

```

---

<div class="post-metadata">

**Author:** ![MonkeybreadSoftware](https://ifnotnil.com/user_avatar/ifnotnil.com/monkeybreadsoftware/32/451_2.png) [@MonkeybreadSoftware](https://ifnotnil.com/u/MonkeybreadSoftware)\
**Post date:** [18 January 2021 06:56 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/2 "2021-01-18T06:56:24Z")

</div>

Why not compare right(4) to “.txt” instead?

---

<div class="post-metadata">

**Author:** ![MarkusWinter](https://ifnotnil.com/user_avatar/ifnotnil.com/markuswinter/32/32_2.png) [@MarkusWinter](https://ifnotnil.com/u/MarkusWinter)\
**Post date:** [18 January 2021 07:59 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/3 "2021-01-18T07:59:38Z")

</div>

What he said 😉

(and yes, I know: I’m cheating)

---

<div class="post-metadata">

**Author:** ![JeffT](https://ifnotnil.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@JeffT](https://ifnotnil.com/u/JeffT)\
**Post date:** [18 January 2021 09:19 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/4 "2021-01-18T09:19:22Z")

</div>

Case sensitive filing system?  
Uppercase the name and test for “.TXT”

test that datafolder is a folder, is not nil, and that it exists.  
This could blow up quite quickly… 🙂

---

<div class="post-metadata">

**Author:** ![TomasJ](https://ifnotnil.com/user_avatar/ifnotnil.com/tomasj/32/4998_2.png) [@TomasJ](https://ifnotnil.com/u/TomasJ)\
**Post date:** [18 January 2021 10:49 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/5 "2021-01-18T10:49:51Z")

</div>

1. Did not crosschecked with Reference but woulnd’t this include folders with txt extensions aswell?
2. I would check for lenght of filenames before trying to use right, left, mid statements e.g. what about a filename just named “txt”
3. as mentioned before this is not upper- and lowercase friendly, simply convert everything to upper or lowercase before comparing
4. this code is poor on performance because it’s interacting with a control and basically locking a program when parsing a folder with thousands of files.

---

<div class="post-metadata">

**Author:** ![MonkeybreadSoftware](https://ifnotnil.com/user_avatar/ifnotnil.com/monkeybreadsoftware/32/451_2.png) [@MonkeybreadSoftware](https://ifnotnil.com/u/MonkeybreadSoftware)\
**Post date:** [18 January 2021 12:46 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/6 "2021-01-18T12:46:32Z")

</div>

> [@JeffT](#):
>
> Uppercase the name and test for “.TXT”

The comparison in Xojo is case insensitive, so this may work on a case sensitive file system.

---

<div class="post-metadata">

**Author:** ![MonkeybreadSoftware](https://ifnotnil.com/user_avatar/ifnotnil.com/monkeybreadsoftware/32/451_2.png) [@MonkeybreadSoftware](https://ifnotnil.com/u/MonkeybreadSoftware)\
**Post date:** [18 January 2021 12:48 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/7 "2021-01-18T12:48:16Z")

</div>

> [@TomasJ](#):
>
> trying to use right, left, mid

You can use Right/Left/Mid without bounds checking exceptions as they adjust your values. So [right](http://docs.xojo.com/Right)(3) on the text “a” gives back “a”. The newer [Middle](http://docs.xojo.com/String.Middle) function would raise an exception.

---

<div class="post-metadata">

**Author:** ![s7g2vp2](https://ifnotnil.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@s7g2vp2](https://ifnotnil.com/u/s7g2vp2)\
**Post date:** [18 January 2021 12:48 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/8 "2021-01-18T12:48:45Z")

</div>

I would say:  
• Check f is not nil  
• Check for the name ending in .txt rather than txt  
• Check that f isn’t a directory

---

<div class="post-metadata">

**Author:** ![npalardy](https://ifnotnil.com/user_avatar/ifnotnil.com/npalardy/32/10_2.png) [@npalardy](https://ifnotnil.com/u/npalardy)\
**Post date:** [18 January 2021 15:26 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/9 "2021-01-18T15:26:44Z")

</div>

this is in a xojo example and seems really wrong  
at least it doesnt match up with the stated purpose of the code

you’ve all basically confirmed for me that this IS a bug and does not match the stated purpose 🙂

---

<div class="post-metadata">

**Author:** ![DaveDuke](https://ifnotnil.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@DaveDuke](https://ifnotnil.com/u/DaveDuke)\
**Post date:** [20 January 2021 20:27 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/10 "2021-01-20T20:27:16Z")

</div>

If you have deep level directory’s won’t it blow xojo’s stack if it calls itself too many times.

---

<div class="post-metadata">

**Author:** ![DaveDuke](https://ifnotnil.com/letter_avatar_proxy/v4/letter/d/8e8cbc/32.png) [@DaveDuke](https://ifnotnil.com/u/DaveDuke)\
**Post date:** [20 January 2021 20:28 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/11 "2021-01-20T20:28:48Z")

</div>

Will it enumerate the volumes folder correctly to scan other disks? And if so will it throw if it comes up a Linux partition ?

---

<div class="post-metadata">

**Author:** ![npalardy](https://ifnotnil.com/user_avatar/ifnotnil.com/npalardy/32/10_2.png) [@npalardy](https://ifnotnil.com/u/npalardy)\
**Post date:** [20 January 2021 20:29 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/12 "2021-01-20T20:29:00Z")

</div>

it would have all those problems since it just checks the folderitems name for the last 3 characters

---

<div class="post-metadata">

**Author:** ![npalardy](https://ifnotnil.com/user_avatar/ifnotnil.com/npalardy/32/10_2.png) [@npalardy](https://ifnotnil.com/u/npalardy)\
**Post date:** [20 January 2021 20:35 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/13 "2021-01-20T20:35:19Z")

</div>

> [@DaveDuke](#):
>
> If you have deep level directory’s won’t it blow xojo’s stack if it calls itself too many times.

the method isnt recursive so no  
unless you’re referring to something other than my original post ?

> [@DaveDuke](#):
>
> Will it enumerate the volumes folder correctly to scan other disks? And if so will it throw if it comes up a Linux partition ?

MAybe  
I havent tried that

This is from the word counter Worker example and I was poking through the code to see how it worked when I noticed this and realized that it doesnt do any checks to see hat the items IS a fIle (not a dirr etc)  
If it is a directory with a name that ends in TXT things blow up since you cant open a directory as a text input stream

I’m sure there’s a “well its JUST example code” somewhere in all this  
But I tend to think that if they are going to post blogs & examples they should be reasonably robust (perhaps not flawless)  
In this case the example says it will count words in files named with a .txt extension - but it doesnt actually verify the extension - just the last 3 chars which is NOT the same thing) nor does it see that its a FILE (it could be a dir named MyDir.txt and things would break)

Thanks for everyones participation & observations on such a short piece of code

---

<div class="post-metadata">

**Author:** ![jmadren](https://ifnotnil.com/user_avatar/ifnotnil.com/jmadren/32/65_2.png) [@jmadren](https://ifnotnil.com/u/jmadren)\
**Post date:** [26 January 2021 17:06 UTC](https://ifnotnil.com/t/spot-the-bug-s/1490/14 "2021-01-26T17:06:28Z")

</div>

Yes, I find these issues on many examples in the docs - they don’t “cover all the bases”.

But then, they have established that their target audience is “simpleton developers”, so of course their examples reflect that.
