Greetings,
I am hoping someone can help me out here.
Currently i am in the process of creating a program that creates a list of files in a given directory, their size, timestamp, and CRC etc... (its for a updater program...) anyway...
Right now i use this piece of code to generate a directory content listing.
Code from Oslink
Code:
#include <windows.h>
#include <winbase.h>
namespace oslink
{
class directory
{
public:
directory(const std::string& aName)
: handle(INVALID_HANDLE_VALUE), willfail(false)
{
// First check the attributes trying to access a non-directory with
// FindFirstFile takes ages
DWORD attrs = GetFileAttributes(aName.c_str());
if ( (attrs == 0xFFFFFFFF) || ((attrs && FILE_ATTRIBUTE_DIRECTORY) == 0) )
{
willfail = true;
return;
}
std::string Full(aName);
// Circumvent a problem in FindFirstFile with c:\\* as parameter
if ( (Full.length() > 0) && (Full[Full.length()-1] != '\\') )
Full += "\\";
WIN32_FIND_DATA entry;
handle = FindFirstFile( (Full+"*").c_str(), &entry);
if (handle == INVALID_HANDLE_VALUE)
willfail = true;
else
current = entry.cFileName;
}
~directory()
{
if (handle != INVALID_HANDLE_VALUE)
FindClose(handle);
}
operator void*() const
{
return willfail ? (void*)0:(void*)(-1);
}
char* next()
{
char* prev = current;
WIN32_FIND_DATA entry;
int ok = FindNextFile(handle, &entry);
if (!ok)
willfail = true;
else
current = entry.cFileName;
return current;
}
private:
HANDLE handle;
bool willfail;
char* current;
};
}
however i will be honest i don't know alot about windows programming, so when i look at alot of this i don't know the windows API well enough to figure out where to change it so that when it finds a directory it will list the files in that directory and the returned string will be like "/directory/file.ext"
In case that didn't make sense here is an example directory structure.
Code:
[Directory1]
--File1.ext
--File2.ext
--[SubDirectory1]
----File3.ext
--[SubDirectory2]
----File4.ext
----File5.ext
--File6.ext
--[SubDirectory3]
----File7.ext
From that i wish to find a way so that my final file listing will be somthing like the following.
Code:
File1.ext
File2.ext
/SubDirectory1/File3.ext
/SubDirectory2/File4.ext
/SubDirectory2/File5.ext
File6.ext
/SubDirectory3/File7.ext
I can assemble the strings and everything later, thats not the issue, I just need the oslink code to return the subdirectory files in the above format (/SubDirectoryX/FileX.ext).
I do so hope that this makes sense, and I really appricate any help you can offer =). If you know of another example of code, or a lib that does this kind of stuff, i am not tied to the oslink one by anymeans.
Thanks again!!!