[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

System commands from c

Steve Holle wrote:

> I there any way to issue a file system command from within c, such as 
> 'ls'?
This is how I list my directory in c

void ListDir(void)
  DIR *dir;
  struct dirent *ent;
  char dir_buffer [100];

  strcpy (dir_buffer, hard_drive ) ;

    if ((dir = opendir(dir_buffer)) == NULL)
            printf ("\r\nUnable to open directory");
            printf ("\r\nListing Directory %s", dir_buffer);
            while ((ent = readdir(dir)) != NULL)
                    printf ("\r\n%s", ent->d_name);
            if (closedir(dir) != 0)
                    printf("\r\nUnable to close directory");


Angelo Fraietta

PO Box 859
Hamilton NSW 2303

Home Page


There are those who seek knowledge for the sake of knowledge - that is CURIOSITY
There are those who seek knowledge to be known by others - that is VANITY
There are those who seek knowledge in order to serve - that is LOVE
    Bernard of Clairvaux (1090 - 1153)