Get list of files with *.dds
#1
Posted 04 May 2009 - 09:37 AM
The basic process would go like this
scan the folder
int numDDSFiles = 0;
for (each file, check dds)
numDDSFiles++;
LPCSTR DirectoryArrays[numDDSFiles];
for(int i = 0; i < numDDSFiles; i++)
{
DirectoryArrays[i] = "Media/LightProbes/" + fileName + "dds";
}
trouble is I don't know how to check how many files there are in a particular file that have a certain file extension, or how to get what that file name is. I'd be happy to use STL or Win32 library and am open to other methods, but as stated above would rather not use boost.
Thanks =)
#3
Posted 05 May 2009 - 04:45 AM
You can implement simple filtering by filename (or extension) like this:
bool CheckUseFile(LPCTSTR, WIN32_FIND_DATA* pwfd)
{
return ::PathMatchSpec(pwfd->cFileName, _T("*.jpg"));
}
although much of the code that is presented in the download file seems very complicated and I'm finding it difficult to understand, is there not an easier way to go about it?
Thanks
#4
Posted 05 May 2009 - 05:05 AM
#5
Posted 05 May 2009 - 05:20 AM
#6
Posted 05 May 2009 - 05:26 AM
#7
Posted 05 May 2009 - 06:10 AM
#8
Posted 05 May 2009 - 07:35 AM
HANDLE hHandle;
WIN32_FIND_DATA* pData = NULL;
std::vector<LPCSTR> Directories;
hHandle = FindFirstFile("Media/LightProbes/", pData);
BOOL bMoreFiles = TRUE;
while(bMoreFiles == TRUE)
{
bMoreFiles = FindNextFile(hHandle, pData);
if(bMoreFiles == TRUE)
{
Directories.push_back(LPCSTR(pData->cFileName));
}
}
but when I check the size of Directories and it is 0, I have checked in the file Media/LightProbes and there are 9 files there, what's happening?
#9
Posted 05 May 2009 - 08:14 AM
HANDLE hHandle;
WIN32_FIND_DATA* pData = NULL;
std::vector<LPCSTR> Directories;
hHandle = FindFirstFile("Media/LightProbes/*", pData);
BOOL bMoreFiles = TRUE;
while(bMoreFiles == TRUE)
{
bMoreFiles = FindNextFile(hHandle, pData);
if(bMoreFiles == TRUE)
{
Directories.push_back(LPCSTR(pData->cFileName));
}
}
Edit: Heh ... the code block appears to get proper confused by a /* in a string ...
#10
Posted 05 May 2009 - 08:55 AM
bool _Buy(size_type _Capacity)
{ // allocate array with _Capacity elements
_Myfirst = 0, _Mylast = 0, _Myend = 0;
if (_Capacity == 0)
return (false);
else if (max_size() < _Capacity)
_Xlen(); // result too long
else
{ // nonempty array, allocate storage
_Myfirst = this->_Alval.allocate(_Capacity);
_Mylast = _Myfirst;
_Myend = _Myfirst + _Capacity;
}
return (true);
}
#11
Posted 05 May 2009 - 09:34 AM
There is another bug though. An LPCSTR is a Long Pointer to a Constant STRing. Basically after you call FindNextFile the pData->cFileName is most probably de-allocated and freed. To fill your structure you should be copying the string to your own allocation (Which you, of course, need to free after you've used it).
So try this code ...
HANDLE hHandle;
WIN32_FIND_DATA* pData = NULL;
std::vector<TCHAR*> Directories;
hHandle = FindFirstFile("Media/LightProbes/*", pData);
BOOL bMoreFiles = TRUE;
while(bMoreFiles == TRUE)
{
bMoreFiles = FindNextFile(hHandle, pData);
if(bMoreFiles == TRUE)
{
const size_t strLen = _tcslen( pData->cFileName ) + 1;
TCHAR* pNewStr = new TCHAR[strLen];
_tcscpy_s( pNewStr, strLen, pData->cFileName );
Directories.push_back( pNewStr );
}
}
#12
Posted 05 May 2009 - 09:41 AM
#13
Posted 05 May 2009 - 09:46 AM
#14
Posted 05 May 2009 - 09:47 AM
#15
Posted 05 May 2009 - 09:49 AM
First-chance exception at 0x7c902128 in RTHDRIBLEngine.exe: 0xC0000005: Access violation writing location 0x00000000.
Unhandled exception at 0x7c902128 in RTHDRIBLEngine.exe: 0xC0000005: Access violation writing location 0x00000000.
#16
Posted 05 May 2009 - 09:54 AM
Read the documentation ...
http://msdn.microsof...418(VS.85).aspx
#17
Posted 05 May 2009 - 09:58 AM
HANDLE hHandle;
WIN32_FIND_DATA data;
std::vector<TCHAR*> Directories;
hHandle = FindFirstFile("Media/LightProbes/*", &data );
BOOL bMoreFiles = TRUE;
while(bMoreFiles == TRUE)
{
const size_t strLen = _tcslen( data.cFileName ) + 1;
TCHAR* pNewStr = new TCHAR[strLen];
_tcscpy_s( pNewStr, strLen, data.cFileName );
Directories.push_back( pNewStr );
bMoreFiles = FindNextFile( hHandle, &data );
}
#18
Posted 05 May 2009 - 10:02 AM
#19
Posted 05 May 2009 - 10:06 AM
rouncer said:
How does that help you to programmatically enumerate files in a directory?
#20
Posted 05 May 2009 - 10:22 AM
HANDLE hHandle;
WIN32_FIND_DATA pData;
std::vector<TCHAR*> Directories;
hHandle = FindFirstFile("Media/LightProbes/*.dds", &pData);
const size_t strLen = _tcslen( pData.cFileName ) + 1;
TCHAR* pNewStr = new TCHAR[strLen];
_tcscpy_s( pNewStr, strLen, pData.cFileName );
Directories.push_back( pNewStr );
BOOL bMoreFiles = TRUE;
while(bMoreFiles == TRUE)
{
bMoreFiles = FindNextFile(hHandle, &pData);
if(bMoreFiles == TRUE)
{
const size_t strLen = _tcslen( pData.cFileName ) + 1;
TCHAR* pNewStr = new TCHAR[strLen];
_tcscpy_s( pNewStr, strLen, pData.cFileName );
Directories.push_back( pNewStr );
}
}
As a note to others, make sure you save the name of whatever cFileName is after FindFirstFile is called otherwise you will miss it out as FindNextFile will not go back to the start of the file, thanks heaps Goz for your help, just another couple of questions if you don't mind?
1. ok, so I've got the name and file extension, how can I effectively go
LPCSTR caPaths[Directories.size()];
for(int i = 0; i < Directories.size(); i++)
{
caPaths[i] = LPCSTR("Media/LightProbes/" + Directory[i]);
}
??
2. What exactly is an "access violation"? I've seen them so many times but never actually known what they are.
Again thank you for your help.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users












