flat assembler
Message board for the users of flat assembler.

Index > Windows > FindFiles recursive

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
A think to keep in mind: FindFirstFile()/FindNextFile() change the current working directory - so your routine should save/restore cwd.

baldr wrote:
hopcode wrote:
important the proc skips JUNCTIONS
That is intentional. I haven't decided yet how to handle hardlinks and symlinks.
How do you distinguish between hard- and symlink? Did a little superficial examination of hardlinks yesterday, and it wasn't obvious how to do this.
Post 03 Feb 2010, 00:04
View user's profile Send private message Visit poster's website Reply with quote
hopcode



Joined: 04 Mar 2008
Posts: 563
Location: Germany
hopcode
baldr wrote:
How...will directories not matching *.asm pattern be found by FindFirst/NextFile?
Oh, yes, sorry for the silly question. I cached the point, found the solution (by user's filters provided on calling the function), than i forgot it and then again i was thinking against it as a not-resolved point. All ok.
Quote:
...instead of pushing current directory on stack and scanning found subdirectory, enqueue it...

One moment...if i understand right, you mean something like first creating a "memory snapshot" of the content of the current-dir, putting all node-items in a list/queue, than processing the queue...
if so, that is a really nice idea...
Very Happy
it could be the right solution...

Thanks a lot,
hopcode
.
.
.
Post 03 Feb 2010, 00:22
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
The pseudocode for such an implementation is pretty simple - implementing it efficiently is left as an exercise for the reader Smile. It doesn't have to be insanely efficient since you're I/O rather than CPU-bound, and normal systems won't have huge amounts of entries in a folder, nor super deeply nested. Still, it's fun to optimize things, isn't it? Smile

Code:
listfiles(startpath,mask,callback)
{
      queue   dirqueue;
   //queue is a FIFO structure: push_back() and pop_front().
       
    dirqueue.push_back(startpath);
      while(!dirqueue.empty())
    {
              currentpath = dirqueue.pop_front();
         foreach(entry in getentries(currentpath, mask))
                     if(entry.isdir && !entry.isjunction)
                                dirqueue.push_back(entry);      // folder, proces later
                     else
                                callback(entry);                        // file, give to callback
   }
}
    
Post 03 Feb 2010, 02:27
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
f0dder wrote:
FindFirstFile()/FindNextFile() change the current working directory
Oh really? Never experienced that.
f0dder wrote:
How do you distinguish between hard- and symlink?
That's simple: symlinks have FILE_ATTRIBUTE_REPARSE_POINT. To detect if found file is hardlink to previously processed file, GetFileInformationByHandle can be used (nFileIndexHigh/Low).
Post 03 Feb 2010, 06:57
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
I always liked the idea of getting an entire directory's entries first, then iterating. Helps with caching I thought...
Post 03 Feb 2010, 07:02
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
sinsi wrote:
I always liked the idea of getting an entire directory's entries first, then iterating. Helps with caching I thought...
Did some tests on a not-so-fast harddrive, and it didn't really seem to make much of a difference - perhaps with optical media it's a different story.

_________________
Image - carpe noctem
Post 03 Feb 2010, 07:14
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.