I tried to find the Win32 tree walker and had trouble finding it. A link could be nice.
Anyway, here is my code again. Not quite working correctly yet but doing better than before. If anyone would help, I would much appreciate it. Here once again is the rundown I am trying to acheive.
Give my program a directory, and fill an array will all paths. example:
Code:
dirs[0] = "C:\";
dirs[1] = "C:\Music\";
dirs[2] = "C:\Videos\";
dirs[3] = "C:\Music\Marley\";
etc...
Here is what I am working with:
Code:
#define _CRT_SECURE_NO_DEPRECATE 1
#include <stdio.h>
#include <string.h>
#include <windows.h>
LPTSTR extensn = "\\";
LPTSTR asteris = "*";
int main (void)
{
WIN32_FIND_DATA f;
DWORD buffSize = MAX_PATH;
LPTSTR lpszBuffer = (LPTSTR)malloc(buffSize *sizeof(char));
LPTSTR tempdir = (LPTSTR)malloc(buffSize *sizeof(char));
LPTSTR basedir = (LPTSTR)malloc(buffSize *sizeof(char));
LPTSTR dirs[1000];
HANDLE h;
int i = 0;
int j = 0;
int k = 0;
sprintf(basedir, "%s", "C:\\Music");
sprintf(lpszBuffer, "%s%s%s", basedir, extensn, asteris);
h = FindFirstFile(lpszBuffer, &f);
while (h != INVALID_HANDLE_VALUE)
{
while (FindNextFile(h, &f))
{
if (f.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
if (strcmp(f.cFileName, "..") != FALSE)
{
sprintf(lpszBuffer, "%s%s%s", basedir, extensn, f.cFileName);
dirs[j] = lpszBuffer;
printf("ADDED %s\t%d\n", dirs[j], j);
j++;
}
}
else
{
printf("FILE FOUND!\n");
//Will try to move it later
}
}
if (j > k)
{
sprintf(lpszBuffer, "%s%s%s", lpszBuffer, extensn, asteris);
h = FindFirstFile(lpszBuffer, &f);
k++;
}
}
//Strange thing here, the array values seem to be different than what I set them to above
for (i = 0; i < j; i++)
printf("%s\n", dirs[j]);
return 0;
}