ryanmills
June 8th, 2009, 02:17 AM
I have a simple function to loop thru the files but for some reason I am only listing the folder its self. I'm sure this is not the best way to do this but does anything jump out as wrong with this. The goal is just to list the file names in the "My Pictures" folder.
#include <iostream>
#include <windows.h>
#include <shlwapi.h>
TCHAR szPath[MAX_PATH];
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError=0;
int main(int argc, char *argv[])
{
SHGetFolderPath(NULL, CSIDL_MYPICTURES, NULL, 0, szPath);
std::cout << "searching: " << szPath << std::endl << std::endl;
hFind = FindFirstFile(szPath, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
std::cout << "folder not found" << std::endl;
}
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
std::cout << "dir: " <<ffd.cFileName << std::endl;
}
else
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
std::cout << "file: " << ffd.cFileName << " size: " << filesize.QuadPart << std::endl;
}
}
while (FindNextFile(hFind, &ffd) != 0);
return 0;
}
// returns
//searching: C:\Documents and Settings\ryanm\My Documents\My Pictures
//dir: My Pictures
The SHGetFolderPath call is returning "C:\Documents and Settings\ryanm\My Documents\My Pictures" however when I point FindFirstFile to that folder it loops once on that folder and only returns that folder. When it should be returning the files inside the folder, even if it was returning the folder below it there should have been more folders but its only seeing "My Pictures". Ideas?
#include <iostream>
#include <windows.h>
#include <shlwapi.h>
TCHAR szPath[MAX_PATH];
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError=0;
int main(int argc, char *argv[])
{
SHGetFolderPath(NULL, CSIDL_MYPICTURES, NULL, 0, szPath);
std::cout << "searching: " << szPath << std::endl << std::endl;
hFind = FindFirstFile(szPath, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
std::cout << "folder not found" << std::endl;
}
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
std::cout << "dir: " <<ffd.cFileName << std::endl;
}
else
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
std::cout << "file: " << ffd.cFileName << " size: " << filesize.QuadPart << std::endl;
}
}
while (FindNextFile(hFind, &ffd) != 0);
return 0;
}
// returns
//searching: C:\Documents and Settings\ryanm\My Documents\My Pictures
//dir: My Pictures
The SHGetFolderPath call is returning "C:\Documents and Settings\ryanm\My Documents\My Pictures" however when I point FindFirstFile to that folder it loops once on that folder and only returns that folder. When it should be returning the files inside the folder, even if it was returning the folder below it there should have been more folders but its only seeing "My Pictures". Ideas?