int my_rmdir (const TCHAR *name) { struct my_opendir_s *od; int cnt; TCHAR tname[MAX_DPATH]; memset(tname, 0, sizeof(TCHAR) * MAX_DPATH); /* SHFileOperation() ignores FOF_NORECURSION when deleting directories.. */ od = my_opendir (name); if (!od) { // SetLastError (ERROR_FILE_NOT_FOUND); return -1; } cnt = 0; while (my_readdir (od, tname)) { if (!_tcscmp (tname, _T(".")) || !_tcscmp (tname, _T(".."))) continue; cnt++; break; } my_closedir (od); if (cnt > 0) { // SetLastError (ERROR_CURRENT_DIRECTORY); return -1; } return rmdir (name); }
void ls_rec(t_mem *s, char *path) { DIR *rep; struct dirent *fichier; t_fil *list; rep = NULL; list = NULL; if (my_opendir(path, &rep, s) != 0) { while ((fichier = readdir(rep)) != NULL) ft_add_file(s, fichier, path, &list); if (my_closedir(path, &rep) != 0) ls_rec2(s, &list, path); } }
/* Find the name REL in directory DIRNAME. If we find a file that * has exactly the same name, return REL. If we find a file that * has the same name when compared case-insensitively, return a * malloced string that contains the name we found. If no file * exists that compares equal to REL, return 0. */ TCHAR *fsdb_search_dir (const TCHAR *dirname, TCHAR *rel) { TCHAR *p = 0; struct dirent *de; TCHAR fn[MAX_DPATH]; struct my_opendir_s *dir = my_opendir (dirname); /* This really shouldn't happen... */ if (! dir) return 0; while (p == 0 && (de = my_readdir (dir, fn)) != 0) { if (strcmp (de->d_name, rel) == 0) p = rel; else if (strcasecmp (de->d_name, rel) == 0) p = my_strdup (de->d_name); } my_closedir (dir); return p; }
/* dirwalk: aplica fcn a todos los archivos de dir */ void dirwalk( char *dir, void (*fcn)(char *) ){ char name[ MAX_PATH ]; Dirent *dp; myDIR *dfd; if( (dfd = my_opendir( dir )) == NULL ){ fprintf( stderr, "dirwalk: no se puede abrir %s\n", dir ); return; } while( (dp = my_readdir( dfd )) != NULL ){ if( strcmp( dp->name, "." ) == 0 || strcmp( dp->name, ".." ) ) continue; /* se ignora a si mismo y a su padre */ if( strlen( dir ) + strlen( dp->name ) + 2 > sizeof( name ) ) fprintf( stderr, "dirwalk: nombre %s %s demasiado largo\n", dir, dp->name ); else { sprintf( name, "%s/%s", dir, dp->name ); (*fcn)( name ); } } my_closedir( dfd ); }
struct my_opendir_s *my_opendir (const TCHAR *name) { return my_opendir (name, ""); }
struct my_opendir_s *my_opendir (const TCHAR *name) { return my_opendir (name, _T("*.*")); }