|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming | |
C++ Searching for a Directory
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||
|
Overclocker
|
Hello, I am trying to figure out how to go about searching for a directory on my C:\ volume using C++. Any help would be appreciated.
__________________![]()
|
|||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Programmer
|
Well, C++ isn't really the language you'd want to use for searching for files and directories. The main reason being all platforms have different ways of storing the directory tree structure. What will work in windows wont work in a unix environment. You could either run a script outside of the C++ program, or try using a platform specific library. Alternatively, you could check out Boost's Filesystem Library, seen here. While I have used Boost before, I've never used this particular library, so you'll probably want to check elsewhere (including Boost's site) for more info. Hope this helps.
__________________
Whats this folding I've been hearing about? Crucial Ballistix Club ![]() Member of the OCN Diablo III Club ~M Hail to the Victors M~
|
|||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||
|
Overclocker
|
Well this is a start. I am just trying to get familiar with C++ and my friend gave me the idea for this little program to help me. I am not really too concerned with program portability. Long as I can get it to work on Windows I am fine. I will check the site out when I get home later. Thank you.
__________________
|
|||||||||||
|
|
|
|
|
#4 (permalink) | ||||||||||||
|
WaterCooler
|
Just use the Win32 API in C++.
__________________
Michael Check out my Wolf in Sheep's clothing build log New build log BlackBox aka Nagal's folly as it was never finished Duct Tape Fan Shroud Representing the Ghetto Mod Community
|
||||||||||||
|
|
|
|
|
#5 (permalink) | |||||||||||||
|
Programmer
|
If you're just trying to get aquainted with C++, doing directory stuff probably isn't the best place to start, unless you have programming experience in other languages. Just an opinion though.
__________________
Whats this folding I've been hearing about? Crucial Ballistix Club ![]() Member of the OCN Diablo III Club ~M Hail to the Victors M~
|
|||||||||||||
|
|
|
|
#6 (permalink) | |||||||||||
|
Overclocker
|
WIN32 API, not that familiar but I will see what I can find. I am just trying to figure out some basic programs I can try to make in order to better understand the abilities of C++.
__________________
|
|||||||||||
|
|
|
|
|
#7 (permalink) | |||||||||||||
|
Programmer
|
How much coding have you done (in C++ or other languages)? If you're pretty confident then something like...
Read in two text files with one word on each line, alphabetize all the words and write them to a new text file. ..might be a good little exercise. If that seems to advanced or basic let me know and I'll dig through old homework or whatever to find something else for you to try out.
__________________
"He attacked everything in life with a mix of extraordinary genius and naive incompetence, and it was often difficult to tell which was which." Douglas Adams
|
|||||||||||||
|
|
|
|
|
#8 (permalink) | ||||||||||||
|
Overclocker in Training
|
search for CFileFind in msdn
|
||||||||||||
|
|
|
|
|
#9 (permalink) |
|
New to Overclock.net
|
...or use the Boost Filesystem library (the following code example is from the two-minute tutorial)
Code:
#include "boost/filesystem.hpp" // includes all needed Boost.Filesystem declarations
#include <iostream> // for std::cout
using boost::filesystem; // for ease of tutorial presentation;
// a namespace alias is preferred practice in real code
bool find_file( const path & dir_path, // in this directory,
const std::string & file_name, // search for this name,
path & path_found ) // placing path here if found
{
if ( !exists( dir_path ) ) return false;
directory_iterator end_itr; // default construction yields past-the-end
for ( directory_iterator itr( dir_path );
itr != end_itr;
++itr )
{
if ( is_directory(itr->status()) )
{
if ( find_file( itr->path(), file_name, path_found ) ) return true;
}
else if ( itr->leaf() == file_name ) // see below
{
path_found = itr->path();
return true;
}
}
return false;
}
|
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|