For the first example based on your images - > "/Users/cristoferfb/Documents/Universidad"
I did a similar test and it does not work because fgets()
reads / captures the newline
for example try the following:
if(isspace(dir[strlen(dir)-1]))
dir[strlen(dir)-1]=' char dir[250];
DIR *carpeta;
struct dirent *archivo;
//CLEAR
printf("Arrastre la carpeta a la ventana o ingrese la direccion para indexar\n");
fgets(dir,250,stdin);
if(isspace(dir[strlen(dir)-1]))
dir[strlen(dir)-1]=' char dir[250];
DIR *carpeta;
struct dirent *archivo;
//CLEAR
printf("Arrastre la carpeta a la ventana o ingrese la direccion para indexar\n");
fgets(dir,250,stdin);
if(isspace(dir[strlen(dir)-1]))
dir[strlen(dir)-1]='if(isspace(dir[strlen(dir)-1]))
dir[strlen(dir)-1]=' char dir[250];
DIR *carpeta;
struct dirent *archivo;
//CLEAR
printf("Arrastre la carpeta a la ventana o ingrese la direccion para indexar\n");
fgets(dir,250,stdin);
if(isspace(dir[strlen(dir)-1]))
dir[strlen(dir)-1]=' char dir[250];
DIR *carpeta;
struct dirent *archivo;
//CLEAR
printf("Arrastre la carpeta a la ventana o ingrese la direccion para indexar\n");
fgets(dir,250,stdin);
if(isspace(dir[strlen(dir)-1]))
dir[strlen(dir)-1]='%pre%';
int j = 0;
while (dir[j] != '%pre%'){
if (dir[j] == '\' ) {
int idx = j;
memmove(&dir[idx], &dir[idx + 1], strlen(dir) - idx);
}
j++;
}
carpeta = opendir(dir);
if (carpeta != NULL){
while ((archivo = readdir(carpeta))) puts (archivo->d_name);
closedir(carpeta);
}else
perror ("Error al abrir el directorio ");
getchar();
';
carpeta = opendir(dir);
if (carpeta != NULL){
while ((archivo = readdir(carpeta))) puts (archivo->d_name);
closedir(carpeta);
}else
perror ("Error al abrir el directorio ");
getchar();
';
';
int j = 0;
while (dir[j] != '%pre%'){
if (dir[j] == '\' ) {
int idx = j;
memmove(&dir[idx], &dir[idx + 1], strlen(dir) - idx);
}
j++;
}
carpeta = opendir(dir);
if (carpeta != NULL){
while ((archivo = readdir(carpeta))) puts (archivo->d_name);
closedir(carpeta);
}else
perror ("Error al abrir el directorio ");
getchar();
';
carpeta = opendir(dir);
if (carpeta != NULL){
while ((archivo = readdir(carpeta))) puts (archivo->d_name);
closedir(carpeta);
}else
perror ("Error al abrir el directorio ");
getchar();
';
.
%pre%
I can not try to drop the directories in the terminal because the one I use does not accept that, but the system it uses is very similar and works for such a route.
/ruta/a/sin/espacios_ni_descendente
If it does not work for that style of routes, you have to clean the \
before passing them to opendir
see if content of dir
after using if(isspace...
have those characters and replace them. but as I say this part I can not look at it, even the first error is because of what is said about fgets
.
With \
I mean /Users/cristoferfb/Documents/Universidad/Estructura\ de\ datos
UPDATE:
I've done some tests and with a path like this /Users/cristoferfb/Documents/Universidad/Estructura de datos
or like this other /Users/cristoferfb/Documents/Universidad/Estructura de datos.
should work, what I mean is that when you set dir
and after apliar the if(isspace...
apply a function remove the \ backslash, but leave the next space as shown above. This I think should be enough but if not, try to add a .
at the end
I'll give you an example (take it as a pseudocode) because it is made to illustrate and although it works it can be improved.
%pre%