Re: Deleting directory on Windows.

Harring Figueiredo <[email protected]>
Newsgroups gmane.comp.video.gimp.windows.devel
Message-ID <[email protected]>
  Thanks for the code! I will modify to fit my needs.

   The bug is actually documented on the remove(3) man page.

Except from the GNU remove(3) man page.

"NOTE
       Under libc4 and libc5, remove was an alias for unlink (and
       hence would not remove directories)."


  What happens on Windows is that if I use remove() to remove a dir, I get a
permission denied. If I use rmdir(), it works fine. 

  Thanks again for the help.

Harrring.






--- Evil Kosh <[email protected]> wrote:
> Hi,
> 
> You can use the function rmdir(char *path);
> 
> it works for me, if you want to recurse, you're going to have to do some 
> system specific stuff, perhaps an abstraction layer, or an #ifdef pair
> 
> if you want to recurse, I suppose this code would work on win32.
> 
> <code>
> 
> bool VFSHandle_file::DeleteDir(char *directory, bool recurse)
> {
>          char path[256];
> 
>          sprintf(path,"%s/*.*",directory);
> 
>          if(recurse==true){
>                  _finddata_t find;
> 
>                  long Filehandle = _findfirst(path,&find);
> 
>                  if(Filehandle == -1){
>                          if(errno == ENOENT){
>                                  _findclose(Filehandle);
>                                  return DeleteDir(directory,false);
>                          }
> 
>                          if(errno == EINVAL){
>                                  _findclose(Filehandle);
>                                  return false; // should this happen ever 
> with *.* ? I dont think so....
>                          }
>                  }else{
>                          do{
>                                  if(strcmp(find.name,".") != 0 && 
> strcmp(find.name,"..") != 0){
>                                          memset(path,0,256);
>                                         
> sprintf(path,"%s/%s",directory,find.name);
>                                          Deletefile(path);
>                                  }
>                          }while(_findnext(Filehandle,&find) == 0);
> 
>                          _findclose(Filehandle);
>                          return DeleteDir(directory,false);
>                  }
> 
>                  //      have to delete all the files in the folder, then 
> remove it, all the way back to the root directory requested to delete
> 
>                  return false;
>          }
> 
>          if(rmdir(directory) == -1){
>                  if(errno == ENOTEMPTY)  return false;
>                  if(errno == ENOENT)                     return false;
>          }
> 
>          return true;
> }
> 
> </code>
> 
> That would recursively delete a directory for you, you'll notice I used an 
> object to contain the win32 code apart from the linux code, but I Suppose 
> any method which has the same effect would be nice.
> 
> By the way, what IS the bug with remove() on linux? I dont know and I've 
> tried looking on google but with so many results I can't find the specific
> bug.
> 
> thanks
> 
> kosh
> 
> At 10/10/2002 15:00, you wrote:
> 
> 
> >  I am trying not to use system.. but I guess I will have to resort to that.
> >
> >  I could use  remove("path");  but it seems that it uses libc4/5 and it has
> a
> >bug.
> >
> >  Thanks for the help.
> >
> >  What woule be the diference between deldir and deltree ?
> >
> >  Thanks.
> >
> >Harring.
> >--- Chris Nystrom <[email protected]> wrote:
> > > On Thu, 10 Oct 2002, harringf wrote:
> > >
> > > >  Is there an easy way to delete directories ( with files ) from within
> > > > a program.
> > >
> > > Off the top of my head, how about something like:
> > >
> > > #ifdef WIN32
> > >   system("deldir <dirname>");
> > > #endif
> > >
> > > Chris
> > >
> > >
> > >
> >
> >
> >__________________________________________________
> >Do you Yahoo!?
> >Faith Hill - Exclusive Performances, Videos & More
> >http://faith.yahoo.com
> >
> >
> >To Post a message, send it to:   [email protected]
> >To Unsubscribe, send a blank message to: [email protected]
> >
> >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
> >
> >
> >
> >---
> >Incoming mail is certified Virus Free.
> >Checked by AVG anti-virus system (http://www.grisoft.com).
> >Version: 6.0.400 / Virus Database: 226 - Release Date: 09/10/2002
> > 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.400 / Virus Database: 226 - Release Date: 09/10/2002
> 


__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.