System commands from c

Angelo Fraietta afraiett at bigpond.net.au
Mon May 10 22:06:16 UTC 2004


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");
        }
    else
        {
            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


http://www.users.bigpond.com/angelo_f/

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)






More information about the users mailing list