[gameprogrammer] Linux _findfirst equivalent
- From: Kevin Jenkins <gameprogrammer@xxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Sat, 10 Jun 2006 09:02:01 -0700
This code is supposed to add all non-hidden files and files in
subdirectories from applicationDirectory/subDirectory through the member
function AddFile
Linux doesn't know what _findfirst is though. Any ideas?
FileList.cpp: In member function `void
FileList::AddFilesFromDirectory(const char*, const char*, bool)':
FileList.cpp:73: error: `_finddata_t' undeclared (first use this function)
FileList.cpp:73: error: (Each undeclared identifier is reported only
once for each function it appears in.)
FileList.cpp:73: error: expected `;' before "fileInfo"
FileList.cpp:111: error: `fileInfo' undeclared (first use this function)
FileList.cpp:111: error: `_findfirst' undeclared (first use this function)
FileList.cpp:114: error: `_findclose' undeclared (first use this function)
FileList.cpp:121: error: `_findnext' undeclared (first use this function)
FileList.cpp:126: error: `_A_HIDDEN' undeclared (first use this function)
FileList.cpp:126: error: `_A_SUBDIR' undeclared (first use this function)
FileList.cpp:126: error: `_A_SYSTEM' undeclared (first use this function)
void FileList::AddFilesFromDirectory(const char *applicationDirectory,
const char *subDirectory, bool writeHashInsteadOfData)
{
DataStructures::Queue<char*> dirList;
char root[260];
char fullPath[520];
_finddata_t fileInfo;
intptr_t dir;
int file;
FILE *fp;
CSHA1 sha1;
char *dirSoFar, *fileData;
dirSoFar=new char[520];
if (applicationDirectory)
strcpy(root, applicationDirectory);
else
root[0]=0;
int rootLen=(int)strlen(root);
if (rootLen)
{
strcpy(dirSoFar, root);
if (dirSoFar[strlen(dirSoFar)-1]!='/' &&
dirSoFar[strlen(dirSoFar)-1]!='\\')
{
strcat(dirSoFar, "/");
rootLen++;
}
}
else
dirSoFar[0]=0;
if (subDirectory)
{
strcat(dirSoFar, subDirectory);
if (dirSoFar[strlen(dirSoFar)-1]!='/' &&
dirSoFar[strlen(dirSoFar)-1]!='\\')
strcat(dirSoFar, "/");
}
dirList.Push(dirSoFar);
while (dirList.Size())
{
dirSoFar=dirList.Pop();
strcpy(fullPath, dirSoFar);
strcat(fullPath, "*.*");
dir=_findfirst(fullPath, &fileInfo ); // .
if (dir==-1)
{
_findclose(dir);
delete [] dirSoFar;
unsigned i;
for (i=0; i < dirList.Size(); i++)
delete [] dirList[i];
return;
}
file=_findnext(dir, &fileInfo ); // ..
file=_findnext(dir, &fileInfo );
while (file!=-1)
{
if ((fileInfo.attrib & (_A_HIDDEN | _A_SUBDIR |
_A_SYSTEM))==0)
{
strcpy(fullPath, dirSoFar);
strcat(fullPath, fileInfo.name);
fileData= new char [fileInfo.size];
fp = fopen(fullPath, "rb");
fread(fileData, fileInfo.size, 1, fp);
fclose(fp);
if (writeHashInsteadOfData)
{
sha1.Reset();
sha1.Update( ( unsigned char* ) fileData, fileInfo.size );
sha1.Final();
AddFile((const char*)fullPath+rootLen, (const char*)sha1.GetHash(),
20, fileInfo.size);
}
else
{
AddFile(fullPath+rootLen, fileData, fileInfo.size, fileInfo.size);
}
delete [] fileData;
}
else if ((fileInfo.attrib & _A_SUBDIR) && (fileInfo.attrib &
(_A_HIDDEN | _A_SYSTEM))==0)
{
char *newDir=new char[520];
strcpy(newDir, dirSoFar);
strcat(newDir, fileInfo.name);
strcat(newDir,"/");
dirList.Push(newDir);
}
file=_findnext(dir, &fileInfo );
}
_findclose(dir);
delete [] dirSoFar;
}
}
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- Follow-Ups:
- [gameprogrammer] Re: Linux _findfirst equivalent
- From: Enrico Zschemisch
- References:
- [gameprogrammer] Re: issues with Calculating texture coordinates
- From: Gautam Narain
Other related posts:
- » [gameprogrammer] Linux _findfirst equivalent
- » [gameprogrammer] Re: Linux _findfirst equivalent
- » [gameprogrammer] Re: Linux _findfirst equivalent
- » [gameprogrammer] Re: Linux _findfirst equivalent
- » [gameprogrammer] Re: Linux _findfirst equivalent
- » [gameprogrammer] Re: Linux _findfirst equivalent
- » [gameprogrammer] Re: Linux _findfirst equivalent
- » [gameprogrammer] Re: Linux _findfirst equivalent
--------------------- To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- [gameprogrammer] Re: Linux _findfirst equivalent
- From: Enrico Zschemisch
- [gameprogrammer] Re: issues with Calculating texture coordinates
- From: Gautam Narain