So...how can i get the number of files in a folder? Is it possible to get the names too?
So...how can i get the number of files in a folder? Is it possible to get the names too?
Try this, I converted this from Randy Birch's VBnet code, just for you
It's just a little function that takes the source dir (and "*.*" for all files) and returns the number of files present in it. I can't guarantee it'll work (I'm at school atm, so I can't test it), but I'm sure someone will correct me...
Code:int rgbCountFilesAll(char *sPath) { WIN32_FIND_DATA wfd; long hFile; BOOL bNext = TRUE; long fCount = 0; hFile = FindFirstFile(sPath, &wfd); if (hFile == INVALID_HANDLE_VALUE) //no match, so bail out return 0; end if //must have at least one, so ... if (hFile) while (bNext != FALSE) { fCount++; bNext = FindNextFile(hFile, &wfd); } end if //Close the search handle FindClose(hFile); //return the number of files found return fCount; }
I'll try this, thank you very much for your help!!! (i would say much but i'm french and i haven't the vocable )
More to get the names here.
http://www.cprogramming.com/cboard/s...&threadid=9628
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
the following code works .... it is part of one of my programs...
it loads a list box with with the file names in the give path
Code://** Loads a list box with the files in sPath //** filter files with the extension sFilter i.e. "mdb" "txt" //** returns the number of files loaded... -1 for invalid dir int CMyDialog::LoadFileList(CString sPath, CString sFilter, CListBox *pListBox) { CFileFind ffind; BOOL bWorking; CString sFileName; int iFileCount = 0; //** Set up for wild characters if( sFilter.Find(".*") >= 0) sFilter.TrimRight("*"); if( sFilter.Find("*.") == 0) sFilter.TrimLeft("*"); sPath.TrimRight("\\"); sPath += _T("\\*.*"); //** Verify that it is a valid path bWorking = ffind.FindFile(sPath); if( bWorking == 0) return -1; //** Verify that the list box is not NULL if( pListBox == NULL ) return -1; //** Reset the content of the list box pListBox->ResetContent(); while( bWorking != 0) { bWorking = ffind.FindNextFile(); if( bWorking != 0) { sFileName = ffind.GetFileName(); //** If the file name holds the filter as a substring //** but do not load the files "." and ".." if( sFileName.Find( sFilter ) >= 0 && sFileName.Find(".") > 0) { if( pListBox->FindStringExact(-1, sFileName) < 0 ) pListBox->AddString( sFileName ); iFileCount++; } } } return iFileCount; }
zMan
I was also wondering this... I didnt know it would equal false!
Thanks, SPH