0

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

2
Contributors
2
Replies
4
Views
9 Years
Discussion Span
Last Post by tonyaim83
0

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

0

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");

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.