Hello I have the following code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <dirent.h> // Libreria encargada del tema de los directorios
#include <string.h>
void load(){
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);
carpeta = opendir(dir);
if (carpeta != NULL){
while ((archivo = readdir(carpeta))) puts (archivo->d_name);
closedir(carpeta);
}else
perror ("Error al abrir el directorio ");
getchar();
}
Given an address of a folder, it lists the files inside it, the problem is that it just doesn't read the files when I drag them to the console, but it does when I type the address directly into the file.c
Here drag the folder to the window:
Here I made a change in the code and directly entered the same address of the folder that I dragged
carpeta = opendir("/Users/cristoferfb/Documents/Universidad");
As you can see on the second occasion it performs its task without any problem.
It should be noted that when entering folders with spaces in the names, strange symbols are generated:
those \
are not part of the name and I have tried to remove them but in the end it does not work either.
ps: I am working under macOs Sierra with gcc