I have an array allocated to take 1000 strings.
How can i delete this arrays?
This is my code:
CODE
void CFileCleanDlg::Prefetch(void)
{
//giva all allocated arrays a value
for(int n = 0;n <= 1000;n++)
{
PathArray[n] = "";
SearchArray[n] = "";
}
//search for all folders in C drive
SearchDir("C:\\");
}
void CFileCleanDlg::SearchDir(char* Dir)
{
//variables
CString Path = Dir;
CString SPath = Dir;
CString FileName;
char Directory[MAX_PATH];
bool Search = true;
int Array = Arraybk;
SPath += "*";
//search for the first file/folder
FFind = FindFirstFile((LPCTSTR)SPath,&FindFileData);
//if its a folder continue
if(FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
//if the folder is NOT . or .. continue
if(IsDot(FindFileData.cFileName) == FALSE)
{
//search in the array to check if we already searched in this folder
if(NewPath(FindFileData.cFileName,Arraybk) == TRUE)
{
//Assign path with the full search path ex:C:\\Program Files\\Whatever\\*
Path += FindFileData.cFileName;
SPath = Path;
Path += "\\";
//add found folders to the listBox
m_List.InsertItem(0,Path);
m_List.Update(0);
//convert CString to char[256]
sprintf_s(Directory,"%s",Path);
//Allocate memory for the array
PathArray[Arraybk] = new char[strlen(FindFileData.cFileName)+1];
//Add the folders name to the folder name array to later check if we already serched on it
strcpy(PathArray[Arraybk],FindFileData.cFileName);
//Allocate memory for the 2nd array
SearchArray[Arraybk] = new char[strlen(Directory)+1];
//Add the full serach path to the path array to later use it to move backwards to the last folder.
strcpy(SearchArray[Arraybk],Directory);
//self explanatory
Arraybk++;
Array = Arraybk;
//call this function again with the new full serach path
SearchDir(Directory);
}
}
}
//find next file/folder
while(FindNextFile(FFind,&FindFileData))
{
//if is a folder continue
if(FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
{
//if it is NOT . or .. continue
if(IsDot(FindFileData.cFileName) == FALSE)
{
//search in the array to check if we already searched in this folder
if(NewPath(FindFileData.cFileName,Arraybk) == TRUE)
{
//Assign path with the full search path ex:C:\\Program Files\\Whatever\\*
Path += FindFileData.cFileName;
SPath = Path;
Path += "\\";
//inserts folder name in listBox
m_List.InsertItem(0,Path);
m_List.Update(0);
//convert CString to char[256]
sprintf_s(Directory,"%s",Path);
//Allocate memory for the array
PathArray[Arraybk] = new char[strlen(FindFileData.cFileName)+1];
//Add the folders name to the folder name array to later check if we already serched on it
strcpy(PathArray[Arraybk],FindFileData.cFileName);
//Allocate memory for the array
SearchArray[Arraybk] = new char[strlen(Directory)+1];
//Add the full serach path to the path array to later use it to move backwards to the last folder.
strcpy(SearchArray[Arraybk],Directory);
//self explanatory
Arraybk++;
Array = Arraybk;
//call this function again with the new full serach path
SearchDir(Directory);
}
}
}
}
//finish the serach and delete the search handle
FindClose(FFind);
}
bool CFileCleanDlg::IsDot(char* str)
{
//check if the found folder is not . or ..
if(strcmp(str,".") && strcmp(str,"..") != 0)
return FALSE;
//else
return TRUE;
}
bool CFileCleanDlg::NewPath(char* str,int Array)
{
//search the whole array checking if the folder name someware in it
for(int n = 0;n <= 1000;n++)
{
//compare array strings to the folder name
if(strcmp(str,PathArray[n]) == 0)
{
//if found the name then we already searched in that folder
return FALSE;
}
}
//if not then add the folder name to the array and keep searching
return TRUE;
}
Hope is documented enogh
If i don't delete the array i get this msg

and if i do delete it,it gives me this msg

I know all the problems i'm having is because of the array.