home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / MOVEOS2.ZIP / MOVE.C next >
Text File  |  1988-06-06  |  3KB  |  110 lines

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