-
November 10th, 2014, 12:35 PM
#1
FindNextFile() Looping and Backwards ?
Hi guys, I'm using FindFirstFile() and FindNextFile() to go through all the files in a directory, I want to be able to go backwards and also loop at the beginning and end, like this:
001.txt
002.txt
003.txt
004.txt
...if I am at 003.txt and select back command it should go to 002.txt, if I am at 001.txt and select back command it should go to 004.txt.
For forward looping I can start the process over again with FindFirstFile() but I am not sure if that is smart.
I know that I can store all the filenames in an array but some directories may have 10k file counts so maybe that's not a good idea ?
Thank you.
-
November 10th, 2014, 12:44 PM
#2
Re: FindNextFile() Looping and Backwards ?
Why? What are you trying to accomplish?
In the grand scheme of things, a 10K array isn't that big. If the average file name were 15 characters long, that's only 150K plus a bit of overhead.
-
November 10th, 2014, 01:09 PM
#3
Re: FindNextFile() Looping and Backwards ?
I want to be able to go backwards and also loop at the beginning and end, like this:
As far as I am aware there is no win32 API that provides the ability to start at the end of a directory and go backwards through the files. Also note that using FindFirstFile() and FIndNextFile() says nothing about the order in which the names of the files will be retrieved.
If you want to be able to process/display the file names in a particular order or to traverse the file names in a particular way (eg backwards) then you will need to build a container (eg vector) with the file names, sort the container as required and then iterate through the container which can be forwards or backwards.
As GCDEF says in post #2, a vector of 10k elements isn't that big and is easily handled.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
November 10th, 2014, 04:07 PM
#4
Re: FindNextFile() Looping and Backwards ?
You guys are right, it's better to go with a filename array. It was pretty easy to implement and it's working great.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|