home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / OS2MOVE.LZH / MOVE.C next >
Text File  |  1989-03-30  |  4KB  |  126 lines

  1.  
  2. /************************************************************************
  3.  *                                                                      *
  4.  *      "move.c"   A quick and dirty move utility for OS/2.             *
  5.  *                                                                      *
  6.  *      This program was written as an excercise in C and OS/2          *
  7.  *                                                                      *
  8.  *      This program demonstrates using 3 File functions under OS/2     *
  9.  *                                                                      *
  10.  *      DosFindFirst                                                    *
  11.  *      DosFindNext                                                     *
  12.  *      DosMove                                                         *
  13.  *                                                                      *
  14.  *      Uploaded for Public Domain                                      *
  15.  *                                                                      *
  16.  *      Enjoy.....                                                      *
  17.  *                                                                      *
  18.  *      Tareq AboAlfaraj                                                *
  19.  *                                                                      *
  20.  ************************************************************************/
  21.  
  22.  
  23. #define INCL_DOSFILEMGR
  24. #include <stdio.h>
  25. #include <os2.h>
  26. #include <string.h>
  27. #include <malloc.h>
  28.  
  29. int expand_arg(char *, char **,int *,char *);
  30.  
  31. void main(int argc, char **argv)
  32.  
  33. {
  34.   int i;
  35.   char *from,*to;
  36.   char message[80];
  37.   char source[80];
  38.   char src[80];
  39.   char destin[80];
  40.   char dest[80];
  41.   char *arg[100];
  42.   int count;
  43.  
  44.   if (argc==1)
  45.     {
  46.       puts("usage MOVE [path]filename   [new path]\n\n"
  47.            "Wild Characters are allowed in file name");
  48.       return;
  49.     }
  50.  
  51.   argc--;
  52.  
  53.   if (expand_arg(argv[1],arg,&count,source))
  54.     {
  55.       puts("Error ... File not found ....\n");
  56.       exit(-1);
  57.     }
  58.  
  59.   if (argc!=1)
  60.     {
  61.       strcpy(destin,argv[argc]);
  62.       to = strrchr(destin,'\0');
  63.       to--;
  64.       if (*to!='\\')
  65.         strcat(destin,"\\");
  66.     }
  67.  
  68.   for (i = 0; i < count; i++)
  69.     {
  70.       strcpy(dest,destin);
  71.       strcpy(src,source);
  72.       to = strcat(dest,arg[i]);
  73.       from = strcat(src,arg[i]);
  74.       strcpy(message,"file ");
  75.       strcat(message,from);
  76.       if (DosMove(from,to,0))
  77.         strcat(message," not moved to ");
  78.       else
  79.         strcat(message," moved to ");
  80.       strcat(message,to);
  81.       puts(message);
  82.     }
  83.   exit(0);
  84. }
  85.  
  86. /************************************************************************/
  87.  
  88. int expand_arg(char * name, char * exp_names[], int * argc, char *path)
  89.  
  90. {
  91.   FILEFINDBUF buffer;
  92.   int i=0;
  93.   int n;
  94.   char *pntr,*p;
  95.   unsigned handel=0xffff,count=1;
  96.  
  97.   if ((pntr=strrchr(name,'\\'))!=NULL)
  98.     {
  99.       p = name;
  100.       for(n = 1; p++ != pntr; n++);
  101.       strncpy(path,name,n);
  102.     }
  103.   else if ((pntr = strrchr(name,':')) != NULL)
  104.          {
  105.            p = name;
  106.            for (n = 1; p++ != pntr; n++);
  107.            strncpy(path,name,n);}
  108.        else
  109.          strcpy(path,"");
  110.  
  111.   if (DosFindFirst(name,&handel,0x00,&buffer,sizeof(buffer),&count,0))
  112.     return(-1);
  113.   *argc = i + 1;
  114.   exp_names[0] = malloc(13);
  115.   strcpy(exp_names[0],buffer.achName);
  116.  
  117.   for(;;)
  118.     {
  119.       if (DosFindNext(handel,&buffer,sizeof(buffer),&count))
  120.         return(0);
  121.       exp_names[++i] = (char *) malloc(13);
  122.       strcpy(exp_names[i],buffer.achName);
  123.       *argc=i+1;
  124.     }
  125. }
  126.