Note: Can't use dirent.h library.
I need to modify my program to print files and subdirectories in a directory. Any help would be greatly appreciated.
For example this is what the output should look like:
<DIR> U:\Test\
sample (2).txt 6
sample.txt 6
<DIR> U:\Test\New folder (5)\
sample (4).txt 6
sample (3).txt 6
sample (2).txt 6
sample.txt 6
<DIR> U:\Test\New folder (4)\
sample (5).txt 6
sample (4).txt 6
sample (3).txt 6
sample (2).txt 6
sample.txt 6
<DIR> U:\Test\New folder (3)\
sample.txt 6
<DIR> U:\Test\New folder (2)\
sample (4).txt 6
sample (3).txt 6
sample (2).txt 6
sample.txt 6
<DIR> U:\Test\New folder\
sample -Copy(2).txt 6
sample -Copy.txt 6
sample.txt 6This is what I have so far which only lists the files and subdirectories. I need to able to open the subdirectories and print the associated files. I'm trying to search and print files in seperate functions.
Code:
WIN32_FIND_DATA ffd;
HANDLE hFind = INVALID_HANDLE_VALUE;
size_t lengthOfArg;
TCHAR szDir[MAX_PATH];
LARGE_INTEGER fileSize;
DWORD dwError;
FILE*fp;
do
{
// did we find a directory?
// ffd.dwFileAttributes says this is a directory (FILE_ATTRIBUTE_DIRECTORY)
if(ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
_tprintf(_T("%s <DIR>\n"), ffd.cFileName);
// did we find a file?
else
{
fileSize.LowPart= ffd.nFileSizeLow;
fileSize.HighPart= ffd.nFileSizeHigh;
_tprintf(_T("%s %ld\n"), ffd.cFileName, fileSize.QuadPart);
}
// continue the search; try to find more files
}while(FindNextFile(hFind,&ffd)!=0);