/* op‚ration sp‚cifique sur r‚pertoire */ #include #include #include #include #include "tool.h" #include "../common/commun.h" /* Copie la structure de sous-r‚pertoire d'un path dans un autre Retourne -1 si erreur, 0 si ok */ export int dir_copystruct( const char *refpath, /* reference … utiliser pour cr‚er les dir */ const char *wrkpath) /* destination */ /* si existe pas, tente de cr‚er */ { int ret = 0; if (file_type(wrkpath)==1 || file_mkdir (wrkpath) != -1){ char **tb = (char**)malloc(400); char reftmp[MAXSIZ_PATH]; path_addback(refpath,reftmp); if (tb != NULL){ int lenref = strlen(reftmp); int nbdir = dir_getlistd (refpath,"*.*",100,tb,400); int i; for (i=0; i=0; i--){ char path[MAXSIZ_PATH]; path_make (tb[i],wild,path); ret |= file_unlink (path); if (deldir) ret |= file_rmdir(tb[i]); free (tb[i]); } free (tb); } return (ret); } #ifdef TEST void main(void) { if (file_mkdir ("/tmp/$$$")!=-1){ system ("xcopy /usr/prj1/ /tmp/$$$"); system ("sh"); dir_delete ("/tmp/$$$","*.c"); system ("sh"); dir_delete ("/tmp/$$$",NULL); system ("sh"); dir_copystruct ("/usr/prj","/tmp/prj"); system ("sh"); dir_delete ("/tmp/prj",NULL); }else{ printf ("Ne peut pas cr‚er de r‚pertoire temporaire\n"); } } #endif