#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
void parcoursDossier(char * rep_name);
void executerShellScriptSetFileab(char * fn);
void executerShellNoLbl(char * fn);
char * str_replace(char *str, char *old, char *new);
int main (int argc, char ** argv)
{
parcoursDossier("votre dossier à corriger");
return EXIT_SUCCESS;
}
void parcoursDossier(char * rep_name) {
struct dirent * lecture = NULL;
char ** chemin[1000];
DIR *rep = NULL;
rep = opendir(rep_name);
if (rep != NULL)
{
while ((lecture = readdir(rep)) != NULL)
{
if (!(strcmp(lecture->d_name,"..")==0 || strcmp(lecture->d_name,".")==0)) {
sprintf(chemin,"%s/%s",rep_name,lecture->d_name);
//printf("Traitement de %s\n", chemin);
executerShellScriptSetFileab(chemin);
executerShellNoLbl(chemin);
if(lecture->d_type == DT_DIR) {
//printf("c un rep\n");
parcoursDossier(chemin);
} else {
//printf("c un fichier\n");
}
}
}
}
if (rep != NULL)
{
closedir(rep);
}
}
void executerShellScriptSetFileab(char * fn) {
char ** cmd[1500];
sprintf(cmd, "/Volumes/Macintosh\\ HD/Developer/Tools/SetFile -a ab %s",str_replace(fn," ","\\ "));
system(cmd);
}
void executerShellNoLbl(char * fn) {
char ** cmd[1500];
int res;
sprintf(cmd, "osascript -e \"tell application \\\"Finder\\\" to set label index of alias POSIX file \\\"%s\\\" to 0\"",fn);
//printf(cmd);
res = system(cmd);
}
char * str_replace(char *str, char *old, char *new) {
int i, count = 0;
int newlen = strlen(new);
int oldlen = strlen(old);
for (i = 0; str; ++i)
if (strstr(&str, old) == &str)
++count, i += oldlen - 1;
char *ret = (char *) calloc(i + 1 + count * (newlen - oldlen), sizeof(char));
if (!ret) return;
i = 0;
while (*str)
if (strstr(str, old) == str)
strcpy(&ret, new),
i += newlen,
str += oldlen;
else
ret[i++] = *str++;
ret = '\0';
return ret;
}