Over a million developers have joined DZone.

C - Command "ls"

·

/*
 *
 * Esempio che scansiona una cartella stampando a video i file in essa
 * contenuti.
 */

#include 
#include 
#include 
#include 

int main(int argc, char *argv[])
{
	DIR *dir;
	struct dirent *drent;

	if(argc < 2)
	{
		fprintf(stderr, "%s \n", argv[0]);
		return EXIT_FAILURE;
	}

	if((dir = opendir(argv[1])) == NULL)
	{
		fprintf(stderr, "Errore opendir()\n");
		return EXIT_FAILURE;
	}

	while((drent = readdir(dir)) != NULL)
	{
		fprintf(stdout, "--> %s\n", drent->d_name);
	}
	
	if(closedir(dir) < 0)
	{
		fprintf(stderr, "Errore closedir()\n");
		return EXIT_FAILURE;
	}
}
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}