Hi..
I Want to delete all files in a directory :-

I tried
DeleteFile(".\\ProcFiles\\*.*");

RemoveDirectory(".\\ProcFiles");

But i m not able to delete all files in a directory . I don't have any subfolder in the directory.

Kindly help

you have to iterate through the directory and delete them one at a time. See FindFirstFile() and FileNextFile() to iterate through the directory.

Hi Have done like this now and it is working hope this doesnot have any problem.
If u know any disadvantage of this method kindly let me know that.

DIR *pdir; 
struct dirent *pent;
pdir=opendir(".\\ProcFiles"); 
 if (!pdir)
 {
 cout<<"Directory doesnot exist";
 }
 errno=0; //errno.h
 while ((pent=readdir(pdir)))
 {
  cout<<pent->d_name;
  string file_delete=pent->d_name;
  file_delete= ".\\ProcFiles\\"+file_delete;
  DeleteFile(file_delete.c_str());
 }
 if (errno)
 {
 cout<<"Error while accessing directory";
 }
 closedir(pdir);

RemoveDirectory(".\\ProcFiles");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.