Monday, October 6, 2008

Listing the file names from a directory

Hi all..
This is the source code for listing the file names from a perticuler (specified directory..)..

#include
#include
#include
#include
#include
int _tmain(int argc, TCHAR *argv[])
{
WIN32_FIND_DATA ffd;
LARGE_INTEGER filesize;
TCHAR szDir[MAX_PATH];
size_t length_of_arg;
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError=0;
// SPECIFY THE NAME OF THE DIRECTORY FROM WHERE U WANT TO TAKE THE FILES AS INPUT

szDir[0]='I';szDir[1]=':';szDir[2]='\\';szDir[3]='a';szDir[4]='m';szDir[5]='o';szDir[6]='z'; szDir[7]='\\';szDir[8]='*'; szDir[9]='\0';
hFind = FindFirstFile(szDir, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
{
return dwError;
}
// List all the files in the directory with some info about them.
do
{
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{

}
else
{
filesize.LowPart = ffd.nFileSizeLow;
filesize.HighPart = ffd.nFileSizeHigh;
if(filesize.QuadPart!=0) ////////////////////
{
_tprintf(TEXT(" %s %ld bytes\n"), ffd.cFileName, filesize.QuadPart);
}
}
} while (FindNextFile(hFind, &ffd) != 0);
dwError = GetLastError();
FindClose(hFind);
getch();
return dwError;
}

1 comment:

Unknown said...

Hey, did you left the for loop declaration incomplete on purpose?
Because it's very inconvenient to keep track...