[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fwd: how to delete a directory and its subdirectories with libssh ?


Hi Stéphane

If I'm not mistaken, attributes->name contains only the file/directory
name. When you call your function recursively, you need to build the
full path and pass it to the recursive call. Currently, you attempt to
delete the directories from your working directory.

Regards
Tilo

Am 08.04.2016 um 22:58 schrieb Stéphane Lemoine:
> 
> 
> 
> Hi,
> 
> I cannot delete recursively a directory and its subdirectories,my
> function fails.
> I have a first function that delete all the files in the directory and
> its subdirectory.that first function is ok.
> my second function fails (it tries to delete the directories)
> -c++,qt,libssh-
> 
> 
> 
> boolsshobj::supprimerepserveur(QStringdestdir)
> 
> {
> 
>     int rc;
> 
>     char * p;
> 
>      char dat[10000];
> 
>      bool res=true;
> 
>      p=destdir.toUtf8().data();
> 
>      strcpy(dat,p);
> 
>     
>     sftp_dir dir;
> 
>     sftp_attributes attributes;
> 
> 
>     dir = sftp_opendir(m_sftp, dat);
> 
>     if (!dir)
> 
>     {
> 
> 
>       return false;
> 
>     }
> 
> 
>     while ((attributes = sftp_readdir(m_sftp, dir)) != NULL)
> 
>     {
> 
>         switch(attributes->type)
> 
>         {
> 
> 
>          case SSH_FILEXFER_TYPE_DIRECTORY:
> 
>          {
> 
>                                             QString rep=QString::fromUtf8(attributes->name);
> 
>                                             bool res2=supprimerepserveur(rep);
> 
>                                             if (res2==false)
> 
>                                                 res=false;
> 
> 
> 
>                                             break;
> 
>         }
> 
>         case SSH_FILEXFER_TYPE_REGULAR:
> 
>         {
> 
> 
> 
>                                             break;
> 
>         }
> 
>          case SSH_FILEXFER_TYPE_SYMLINK:
> 
>         {
> 
>             break;
> 
>         }
> 
>          case SSH_FILEXFER_TYPE_SPECIAL:
> 
>         {
> 
>         break;
> 
>         }
> 
>          case SSH_FILEXFER_TYPE_UNKNOWN:{
> 
>                                             break;
> 
>         }
> 
>         }
> 
> 
>        sftp_attributes_free(attributes);
> 
>     }
> 
>     if (!sftp_dir_eof(dir))
> 
>     {
> 
>       sftp_closedir(dir);
> 
>       
> 
>     }
> 
>     rc = sftp_closedir(dir);
> 
>     rc = sftp_rmdir(m_sftp,dat);
> 
> 
>     if(rc<0)
> 
>        res=false;
> 
>     return res;
> 
> 
> 
> 
> }
> 
> 
> do you have any idea ?
> 
> stéphane.
> 
> 


Follow-Ups:
Re: Fwd: how to delete a directory and its subdirectories with libssh ?Stéphane Lemoine <slemoine@xxxxxxxxxxxxx>
References:
Fwd: how to delete a directory and its subdirectories with libssh ?Stéphane Lemoine <slemoine@xxxxxxxxxxxxx>
Archive administrator: postmaster@lists.cynapses.org