Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » I've been using FindFile wrong all these years
I've been using FindFile wrong all these years [message #49317] Thu, 25 January 2018 11:46 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
While porting my applications to Linux I noticed a very strange bug: some files where missing when iterating over folders. After some investigation, it turns out that I've been using FindFile wrong since forever.

I kept wrting loops like this:
FindFile ff("");
while (ff.Next())
    DUMP(ff.GetPath());


This is wrong since it jump over the first file in the folder. On Windows this is not an issue since the first file is always ".." or ".", but under Linux I was missing real important files.

The correct way to write the loop is:
FindFile ff("");
while (ff) {
    DUMP(ff.GetPath());
    ff.Next();
}


Now I need to search for FindFile in all projects ever Smile.

Such a silly problem...


Re: I've been using FindFile wrong all these years [message #49319 is a reply to message #49317] Thu, 25 January 2018 12:58 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi cbporter,

I guess it is designed this way on purpose, so you can write it using for cycle. It ussually seems slightly nicer and requires less lines of code Smile
for(FindFile ff(""); ff; ff.Next()) {
    DUMP(ff.GetPath());
}


Best regards,
Honza
Re: I've been using FindFile wrong all these years [message #49320 is a reply to message #49319] Thu, 25 January 2018 13:10 Go to previous message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Thanks for the information! Might use a for from now on.

As I said, it is a silly mistake which, now that I fixed it across all the projects, turns out it didn't crop up only about 6-7 times. Enough to ruin some features...

Now that I'm aware of it, I won't make it again.

Anyway, I rewrote some of those loops to add the folders into a folder vector and files into a file vector, sort them both and then traverse the vectors. It makes my applications more well behaved on all platforms, since on Linux you get files and folder in random orders.
Previous Topic: Question about SubRange.
Next Topic: Function.h: "expression cannot be used as a function"
Goto Forum:
  


Current Time: Fri Mar 29 12:06:13 CET 2024

Total time taken to generate the page: 0.01729 seconds