Listar archivos en c
Buenas, trato de hacer un programa en c que liste los archivos que hay en un directorio, soy bastante novato, y ayudándome de internet y tal, tengo esto:
-------------------------
#include <Shlwapi.h>
#include <iostream>
#include <Windows.h>
void main(LPCTSTR path)
{
TCHAR searchPath[MAX_PATH];
lstrcpy(searchPath, path);
PathAppend(searchPath, _T("*"));
WIN32_FIND_DATA ffd;
HANDLE sh = FindFirstFile(searchPath, &ffd);
if(INVALID_HANDLE_VALUE == sh) return;
do {
printf("Nombre = %s",ffd.cFileName);
printf("Type = %s", (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "dirn" : "filen" );
} while (FindNextFile(sh, &ffd));
FindClose(sh);
}
-----------------------
Me pone que no existe el identificador _T, y eso lo cojí de una web, y no sé como funciona esa función.
A ver si alguien me puede ayudar con esto o dándome ideas de cómo hacerlo.
Muchas gracias!!
-------------------------
#include <Shlwapi.h>
#include <iostream>
#include <Windows.h>
void main(LPCTSTR path)
{
TCHAR searchPath[MAX_PATH];
lstrcpy(searchPath, path);
PathAppend(searchPath, _T("*"));
WIN32_FIND_DATA ffd;
HANDLE sh = FindFirstFile(searchPath, &ffd);
if(INVALID_HANDLE_VALUE == sh) return;
do {
printf("Nombre = %s",ffd.cFileName);
printf("Type = %s", (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? "dirn" : "filen" );
} while (FindNextFile(sh, &ffd));
FindClose(sh);
}
-----------------------
Me pone que no existe el identificador _T, y eso lo cojí de una web, y no sé como funciona esa función.
A ver si alguien me puede ayudar con esto o dándome ideas de cómo hacerlo.
Muchas gracias!!
para listar archivos en c, has de incluir las librerias
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <fcntl.h>
#define TAM 1024
void leerdirectorios (char buffer[TAM]){
DIR *dirp;
struct dirent *dp;
struct stat datos;
dirp = opendir (buffer);
while ((dp = readdir (dirp))!=NULL)
printf (\\\"%s\\\\n\\\", dp->d_name);
close (dirp);
} // fin de funcion
}
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include <fcntl.h>
#define TAM 1024
void leerdirectorios (char buffer[TAM]){
DIR *dirp;
struct dirent *dp;
struct stat datos;
dirp = opendir (buffer);
while ((dp = readdir (dirp))!=NULL)
printf (\\\"%s\\\\n\\\", dp->d_name);
close (dirp);
} // fin de funcion
}