home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
MOVEOS2.ZIP
/
MOVE.C
next >
Wrap
Text File
|
1988-06-06
|
3KB
|
110 lines
/*
* "MOVE.c" A quick and dirty move utility for OS/2. *
* *
* This program was written as an excercise in C and OS/2 *
* *
* This program demonstrait using 3 File functions under OS/2 *
* *
* DosFindFirst *
* DosFindNext *
* DosMove *
* *
* Uploaded for Public Domain *
* *
* Enjoy..... *
* *
* Tareq AboAlfaraj *
* */
#define INCL_DOSFILEMGR
#include <stdio.h>
#include <os2.h>
#include <string.h>
#include <malloc.h>
int expand_arg(char *, char **,int *,char *);
void main(int argc, char **argv)
{
int i;
char *from,*to;
char message[80];
char source[80];
char src[80];
char destin[80];
char dest[80];
char *arg[100];
int count;
if(argc==1) {
puts("usage MOVE [path]filename [new path]\n\n"
"Wild Characters are allowed in file name");
return;}
argc--;
if(expand_arg(argv[1],arg,&count,source)){
puts("Error ... File not found ....\n");
exit(-1);
}
if(argc!=1){
strcpy(destin,argv[argc]);
to=strrchr(destin,'\0');
to--;
if(*to!='\\')
strcat(destin,"\\");
}
for(i=0;i<count;i++){
strcpy(dest,destin);
strcpy(src,source);
to=strcat(dest,arg[i]);
from=strcat(src,arg[i]);
strcpy(message,"file ");
strcat(message,from);
if(DosMove(from,to,0))
strcat(message," not moved to ");
else
strcat(message," moved to ");
strcat(message,to);
puts(message);
}
exit(0);}
int expand_arg(char * name, char * exp_names[], int * argc, char *path)
{
FILEFINDBUF buffer;
int i=0;
int n;
char *pntr,*p;
unsigned handel=0xffff,count=1;
if((pntr=strrchr(name,'\\'))!=NULL){
p=name;
for(n=1;p++!=pntr;n++);
strncpy(path,name,n);}
else if((pntr=strrchr(name,':'))!=NULL){
p=name;
for(n=1;p++!=pntr;n++);
strncpy(path,name,n);}
else
strcpy(path,"");
if(DosFindFirst(name,&handel,0x00,&buffer,sizeof(buffer),&count,0)) return(-1) ;
*argc=i+1;
exp_names[0]=malloc(13);
strcpy(exp_names[0],buffer.achName);
for(;;){
if(DosFindNext(handel,&buffer,sizeof(buffer),&count)) return(0);
exp_names[++i]=(char *) malloc(13);
strcpy(exp_names[i],buffer.achName);
*argc=i+1;
}}