home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / DOSCOPY.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  2KB  |  60 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /***************************************************
  4.  *      function : copy                            *
  5.  *      purpose  : copy one file                   *
  6.  *                                                 *
  7.  *      arguments: path to source 'fromDir',       *
  8.  *                 path to target 'toDir',         *
  9.  *                 filename to copy 'fname'        *
  10.  *                                                 *
  11.  *      returns  : nothing                         *
  12.  *                                                 *
  13.  *      By       :  Peter Yard (29 May 1991)       *
  14.  ***************************************************/
  15.  
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <io.h>
  19. #include "dosfiles.h"
  20. #include "filnames.h"
  21.  
  22. #define STDOUT fileno(stdout)
  23.  
  24. void copy(char *fromDir, char *fname, char *toDir)
  25. {
  26.       FILE    *nul;       /* nul will redirect stdout to DOS 'nul' */
  27.       char    from[FILENAME_MAX], to[FILENAME_MAX], comd[128];
  28.       int     oldStdout;
  29.  
  30.       /* Create the strings to describe the paths                  */
  31.  
  32.       fnMerge(from, NULL, NULL, fromDir, NULL, fname, NULL);
  33.       fnMerge(to, NULL, NULL, toDir, NULL, fname, NULL);
  34.  
  35.       /* Construct 'comd' string which is a dos command for a copy */
  36.  
  37.       strcpy(comd, "copy ");
  38.       strcat(comd, from); strcat(comd, " ");
  39.       strcat(comd, to);
  40.  
  41.       /* Redirect stdout to a nul file, kills output to the screen */
  42.  
  43.       nul = fopen("NUL", "w");
  44.       oldStdout = dup(STDOUT);
  45.       dup2(fileno(nul), STDOUT);
  46.       fclose(nul);
  47.  
  48.       system(comd);           /* COPY file */
  49.  
  50.       /* Restore stdout and close nul file */
  51.  
  52.       dup2(oldStdout, STDOUT);
  53.       close(oldStdout);
  54.  
  55.       /* Display file source and target,      */
  56.       /* otherwise comment out the next line. */
  57.  
  58.       printf("\n%s copied to %s",from,to);
  59. }
  60.