sequantial processing of files of several directories

K

kkirtac

Hello, i will simply state algorithm of the problem :

root "r" = GetRootDirectory( );
foreach child directory "c" of "r"
foreach file "f" of "c"
process f ;
endfor
endfor

"process" is not important here, the main problem is how i can reach a
directory, how i can visit all of its childs and catch the files of
all childs sequentially.

Regards
 
A

Alf P. Steinbach

* kkirtac:
Hello, i will simply state algorithm of the problem :

root "r" = GetRootDirectory( );
foreach child directory "c" of "r"
foreach file "f" of "c"
process f ;
endfor
endfor

"process" is not important here, the main problem is how i can reach a
directory, how i can visit all of its childs and catch the files of
all childs sequentially.

Check out the Boost library's file and directory support.
 
B

Barry

kkirtac said:
Hello, i will simply state algorithm of the problem :

root "r" = GetRootDirectory( );
foreach child directory "c" of "r"
foreach file "f" of "c"
process f ;
endfor
endfor

"process" is not important here, the main problem is how i can reach a
directory, how i can visit all of its childs and catch the files of
all childs sequentially.

Regards
off-topic I think

I can't see anything related to C++

anyway, there's a hint
File system operation is platform specified
On Windows, check out _FindFirstFile_ on MSDN, or _File_ in Java API
 
J

Jim Langston

kkirtac said:
Hello, i will simply state algorithm of the problem :

root "r" = GetRootDirectory( );
foreach child directory "c" of "r"
foreach file "f" of "c"
process f ;
endfor
endfor

"process" is not important here, the main problem is how i can reach a
directory, how i can visit all of its childs and catch the files of
all childs sequentially.

Since you gave psuedo code and haven't said what OS, etc.. I'll treat this
as an algorithm problem. Not totally OT but...

Normally I would use recursion for this.

root "r" = GetRootDirectory( );
ProcessDirectory( root );
// done

ProcessDirectory( path )
for each entry in path
if entry is file
process file
else if entry is path
ProcessDirectory( path )
endfor
 
K

kkirtac

Since you gave psuedo code and haven't said what OS, etc.. I'll treat this
as an algorithm problem. Not totally OT but...

Normally I would use recursion for this.

root "r" = GetRootDirectory( );
ProcessDirectory( root );
// done

ProcessDirectory( path )
for each entry in path
if entry is file
process file
else if entry is path
ProcessDirectory( path )
endfor

Hello, i m sorry i am on a VC++ - Win32 Console project in Visual
Studio 2005..yes i think i need recursion..i m a bit
complicated..which class to use and how..anyway, wrong place to ask
maybe, thanks
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hello, i m sorry i am on a VC++ - Win32 Console project in Visual
Studio 2005..yes i think i need recursion..i m a bit
complicated..which class to use and how..anyway, wrong place to ask
maybe, thanks

Take a look at the faq, section 5.9 for some suggestions on where better
to ask this question: http://www.parashift.com/c++-faq-lite/
Also, msdn.microsoft.com is a good source and Barry suggested
FindFirstFile() which might be useful.
 
B

BobR

Alf P. Steinbach said:
* kkirtac:

Check out the Boost library's file and directory support.

FWIW: wxWidgets has a nice set of classes for file/directory.
Most people think of wxWidgets as a GUI, but, it has a flag to turn off the
GUI build.
 
J

Jerry Coffin

[ ... ]
Normally I would use recursion for this.

root "r" = GetRootDirectory( );
ProcessDirectory( root );
// done

ProcessDirectory( path )
for each entry in path
if entry is file
process file
else if entry is path
ProcessDirectory( path )
endfor

This gives a depth-first traversal. In many cases, breadth-first
traversal makes better use of caches. A breadth-first traversal would
look something like:

priority_deque directory_list;

add root directory to directory_list

ProcessDirectories(directory_list)

while (there are items in directory_list)
current_directory = first item in directory_list
remove first item from directory list
for each entry in current_directory
if entry is file
process file
else
add entry to directory_list


It's not strictly necessary that the directory list be a priority queue
-- but doing so (sorted by names) automatically gives output in sorted
order, which is often handy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top