| IWishIKnew (460) | |
|
Could someone please explain how I can use the boost library to search for a directory and/or file in any directory? How am I supposed to use an iterator? What does it return? (vector, string, etc) Thank you for your time! (this isn't homework/scvhool work) | |
|
|
|
| IWishIKnew (460) | |
| please?? | |
|
|
|
| clanmjc (661) | |
| http://www.boost.org/doc/libs/1_51_0/libs/filesystem/doc/tutorial.html#Directory-iteration | |
|
|
|
| IWishIKnew (460) | |||
|
Yeah, i know. That doesn't explain what it is. I dont half-ass stuff. What's 'char* argv[]'? It wasnt declared, and yet it's an argument to main(). Let just jump right into it without knowing anything, huh? Lets just start doing it without knowing why
wont even compile, or why it doesnt copy somthing into every folder on your system, or knowing what ostream_iterator does, etc...Please answer my previous question. Thank you. | |||
|
Last edited on
|
|||
| Cubbi (1570) | ||
That's not enough information to help: give the complete source code and the compiler error. Here's that boost tutorial compiled live, online: http://liveworkspace.org/code/a342716e139beb575b0a7d725c45175a (I only hard-coded the directory it's searching since LWS doesn't allow input) | ||
|
Last edited on
|
||
| naraku9333 (919) | |||
| |||
|
Last edited on
|
|||
| IWishIKnew (460) | |
|
@naraku9333 So, why is it a char? And why do we use a pointer ('char*', instead of 'char')? ______________________________________________________________ What does directory_iterator(p) return? An array? A Vector?What is ostream_iterator, and what does it do?where does directory_entry come from? How was it initialized (if it was)? What is it (a string, array, vector, int, etc)?
| |
|
|
|
| clanmjc (661) | ||||||||
It returns an iterator, to the directory, for path 'p'
It is an iterator, that traverses an ostream object.
example:
The directory_iterator() is analogous to myvector.end() Your real questions
e.g. In your C:\ directory you have folders, text files, pictures, videos etc. Each one of these is a directory_entry.
| ||||||||
|
Last edited on
|
||||||||
| IWishIKnew (460) | ||
|
Thank you for the help. So, why do we use 'copy()'? Also: so, how should i 'treat' this iterator? Is it like a vector/array, or does it have it's own properties? when you say
Is there any possible way I could use the iterator to place the directory entries into a vector? Thanky uo for your time! And thank you for being patient with me. | ||
|
|
||
| IWishIKnew (460) | |
Alright, so i got Tut2 to work! Turns out, copy() was not part of the Boost Filesystem library at all... So, now I have JUST 1 MORE QUESTION:How can I have this iterator write it's "findings" to a vector, instead of displaying them? | |
|
|
|
| iseeplusplus (297) | |||
Here's how I've been doing it.
http://www.cplusplus.com/reference/std/iterator/back_inserter/ | |||
|
Last edited on
|
|||
| IWishIKnew (460) | |
|
So, I want to confirm somthing: an iterator is a 'variable type' (if you will). | |
|
|
|
| IWishIKnew (460) | |
|
I have a problem: I'm creating a function to search through all directories, and it will be designed to return a vector<string> of all the matching directories it finds. It will only use a single string, such as "minecraft", or "users", and search your computer until it finds any directory with that string anywhere in its' name. I'm having problems converting boost::filesystem::directory_entry variables into string variables for this operation. Is there any way to convert a directory entry into a string?
| |
|
|
|
| naraku9333 (919) | |||
directory_entry has a path member which has a string member.
| |||
|
|
|||
| IWishIKnew (460) | |
| d.path().string() translates to a string, or is it just d.string()? | |
|
|
|
| naraku9333 (919) | |
|
It looks like either will work, I initially thought directory_entry didn't have a string method. Edit: I'm not particularly experienced with boost so I dont know which would be recommended. | |
|
Last edited on
|
|
| IWishIKnew (460) | |||
|
Alright, thank you! I am having problems. I created a recursive algorithm to search every file/folder on the disk drive for specific keywords in the folder/file names. It works, but (it seems) every time a match is found, and recursively returned, it crashes. I dont have the debugger (i installed boost + minGW and it didnt come with a Debugger... :\ ) so I'm kind of clueless. I did insert some test code (display variables, etc...) and it all points to the recursively returned values. I don't know why It is crashing. Can someone help me out? Here is the recursive algorithm I wrote:
I would really appreciate any help you can give. I know it is in this function, because it always crashes in this function. | |||
|
Last edited on
|
|||
| Cubbi (1570) | |
| would boost's recursive_directory_iterator be more fitting for this task? | |
|
|
|
| IWishIKnew (460) | |
| do I use that in the same way as the regular iterator? | |
|
|
|