Walking Through, Making, Removing Directories
#include "funcs.h"     /**  Walking through directories plus  **/
#include <dirent.h>    /**  a little bit about environments.  **/ 

main(int argc, char **argv)
{
     DIR *dptr;
     struct dirent *dirptr;
     char perlstuff[100], *home;
   
     dptr = opendir(argv[1]);  /* Does no tilde expansion!! NULL on failure! */
   
     while ( (dirptr = readdir(dptr)) != NULL)
     {
        if (strstr(dirptr->d_name, "sig"))  /* Exclude dot file. */
        puts(dirptr->d_name);
     }
     closedir(dptr);

     printf("\n");
     home = getenv("HOME");
     sprintf(perlstuff, "%s/perl", home);
     dptr = opendir(perlstuff); 
         
     while ( (dirptr = readdir(dptr)) != NULL)
     {
        if (strstr(dirptr->d_name, "73"))  /* Exclude dot file. */
        puts(dirptr->d_name);
     }
}
/*****************************  Directory Listing  **************************/

sig3.demo
sig5.demo
signal.demo
sig1.c
sig5.c
sigpipe.c
sigaction.demo
sigchld2.demo
sigchld3.demo
sig4.c
sig6.c
sigchld2.c
sig2.c
sigchld.demo
sig3.c
sigchld.c
sigchld3.c

asg73ab.out
asg73a.pl
asg73ai.pl
asg73aa.pl
asg73a.dat
asg73y.pl
asg73ag.pl
asg73ab.pl
asg73.dat
asg73ae.out
asg73ai.dat
asg73af.out
asg673i.pl
asg73ai.out
asg73x.pl
asg73p.pl
asg73af.pl
asg73aj.pl
asg73ae.pl
asg73.pl

#include "funcs.h"   /**  Making/removing directories.  **/
main()
{
      char line[100];
   
      /*********  Mkdir returns non-zero on failure!   *******/
      mkdir("subfoo", S_IRUSR | S_IWUSR | S_IXUSR | S_IROTH | S_IXOTH);
      system("ls -dl subfoo");

      rmdir("subfoo");    /*****  -1 on failure.  Dirs. must be empty!  *****/
      system("ls -ld subfoo");

      umask(0);
      mkdir("subfoo", S_IRUSR | S_IWUSR | S_IXUSR | S_IROTH | S_IXOTH);
      system("ls -dl subfoo");

      chdir("subfoo");
      system("pwd");
      getcwd(line, 100);   /*****  Returns NULL on error!  *****/
      printf("Current directory is %s.\n\n", line);

      chdir("..");        /* No tilde expansion because sh doesn't know ~! */
      getcwd(line, 100);  /* Get current working directory                 */ 
      printf("Current directory is now %s.\n\n", line);
      
      rename("subfoo", "foodir");  /* -1 on error.  Works with dirs!  */
      system("ls -dl foodir");
      remove("foodir");       /* Allowed for dirs (like rmdir)!  -1 failure */
      system("ls -dl foodir subfoo");
 }
/**************************  SAMPLE EXECUTION  ****************************/

drwx------    2 jwp2286  staff        512 Nov  6 21:01 subfoo

Cannot access subfoo: No such file or directory

drwx---r-x    2 jwp2286  staff        512 Nov  6 21:01 subfoo

/disk2/part6/staff2/jwp2286/sysprog/subfoo

Current directory is /disk2/part6/staff2/jwp2286/sysprog/subfoo.

Current directory is now /disk2/part6/staff2/jwp2286/sysprog.

drwx---r-x    2 jwp2286  staff        512 Nov  6 21:01 foodir

Cannot access foodir: No such file or directory

Cannot access subfoo: No such file or directory