I want to append a binary file. I want to search the current(and possibly other) directory(s) for all files ending with ".exe". How do I specify the correct string for doing this in my ofstream object eg. myOfStreamObject.open("some file name.exe"); ?
Asked
Active
Viewed 303 times
0
-
Wait what exactly are you trying to do? Do you already know the file you want to change to a `.bin`? – Jay Aug 22 '14 at 20:56
-
I apologise if I am not being specific enough! I want to open and append a binary file. But I want to make the program work regardless of what the name is of the binary file in the current directory. In other words, I want to open a binary file, but the ONLY information I have about the file is the fact that is has the extention ".exe" If that makes sense? – Divan Aug 22 '14 at 20:59
-
1Use `boost::filesystem`. Standard C++ has no support for searching directories. Alternatively you can use `grep` in linux, redirect to a file and read the names from your C++ program. – David G Aug 22 '14 at 21:07
-
or `locate` on Linux, or `find` on Linux, AFAIK Windows doesn't have built-in console programs to finding files, you can invoke shell program by using `system` function. – GingerPlusPlus Aug 22 '14 at 21:19
-
1@GingerPlusPlus Windows has API for finding files - see [FindFirstFile](http://msdn.microsoft.com/en-us/library/windows/desktop/aa364418.aspx) et al. Console programs, too - `dir /S` could probably be pressed into service – Igor Tandetnik Aug 22 '14 at 21:28
-
GLib also has nice functions for finding files in a directory – Jay Aug 22 '14 at 21:58
-
see http://stackoverflow.com/questions/306533/how-do-i-get-a-list-of-files-in-a-directory-in-c – Andre Kirpitch Aug 22 '14 at 22:05
-
I'm looking into the boost libraries. It seems to be what I need. Thank you to all who answered. – Divan Aug 23 '14 at 14:53