We no longer offer ftp downloads. If there is a file you need referenced here, please contact me by email and I will get it to you.

IBCOPY.C Tony Lawrence:

download ibcopy.c

/* Copyright 1994 Anthony Lawrence

Archives files to a date, sequence  number format.

For example, IBCOPY DT *.DAT produces (assuming today is 12/31/94)

941231DT.001
941231DT.002
941231DT.003  and so on.  You can add a directory argument also:

IBCOPY MF *.GIF \MYSTUFF produces

\MYSTUFF\941231MF.001
\MYSTUFF\941231MF.002

Note that this is not written to support more than 999 files
being copied with the same tag and directory.  You could
easily modify this to use .aaa, etc. if you want.

*/
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <direct.h>
#include <dos.h>
#include <time.h>

#define Dir_Mask        16
#define Any_Mask        22
#define Showit          1
#define DontShow        0
#define WIDTH           78
struct dta {
char dos_reserved[21];
char flag;
short time;
short date;
long size;
char name[13];
} ;
struct  dta *pd;

void    s_print(struct dta *this);
int     compare(char *this,char *that);
int     makename(char *t,char *u);
int     Wild_control=0;
char S_wild[10][128];
int     savewild(),getwild();
char    *basename(char *string);
char    *qualify(char *p);

char Fname_buf[128];
char CommandBuf[128];
char *Cbuf=CommandBuf;
char Safe[128];
char *Wild=Fname_buf;
int Counter=1;
char *Newname="941006ED.001";
char Dirbuf[128];
char *Archdir=Dirbuf;
char Archbuf[128];
char *Archname=Archbuf;
char *Ext="ED";

main(argc,argv)
int argc;
char **argv;

{
int x;

if (argc < 3)
{
printf("Usage %s TYpe Wildcard [Directory]\n",basename(argv[0]));
printf("Renames as YYMMDDTY.001, etc.)\n");
printf("Example: %s QS BOB.*\n",basename(argv[0]));
printf("produces 941017QS.001, 941017QS.002, etc\n");
printf("Example: %s DQ BOB.*\n",basename(argv[0]));
printf("produces 941017DQ.001, 941017DQ.002, etc\n");
exit(0);
}
strncpy(Ext,argv[1],2);
strcpy(Archdir,".");
strcpy(Wild,argv[2]);
if (argc > 3) strcpy(Archdir,argv[3]);
Wild=qualify(Wild);          /* get args & flags */

do_dir(Any_Mask,Showit);                /* gather data */

}

do_dir(int val,int show)
{
pd=(struct dta *) malloc(sizeof(struct dta));

_asm {
        pusha
        call    setdta
        mov     ah,0x4e
        mov     dx,Wild
        mov     cx,val
        int     0x21
        jb      no_more
d_loop: mov     si,pd
        mov     ax,[si+30]
        cmp     al,'.'
        jz      jfnext
        cmp     show,1
        jz      doshow
        mov     si,pd
        mov     ax,[si+21]
        and     ax,Dir_Mask
        jz      noshow
        add     si,30
        push    si
        mov     ax,Wild
        push    ax
        call    savewild
        call    makename
        pop     ax
        pop     ax
        push    0
        push    Any_Mask
        push    pd
        call    do_dir
        pop     pd
        pop     ax
        pop     ax
        call    setdta
        call    getwild
        jmp     noshow
no_more:jmp     outahere
jfnext: jmp     fnext
doshow: push    pd
        call    showit
        pop     pd
        call    setdta
        jmp     fnext
noshow: mov     si,pd
fnext:  mov     ah,0x4f
        int     0x21
        jb      no_more
        jmp     d_loop
setdta: mov     dx,pd
        mov     ah,0x1a
        int     0x21
        ret
showit: push    pd
        call    s_print
        pop     pd
        ret
outahere:
        popa

     }
}


savewild()
{
if (Wild_control > 9) Wild_control=9;
strcpy(S_wild[Wild_control++],Wild);
}
getwild()
{
strcpy(Wild,S_wild[--Wild_control]);
}
makename(char *string,char *name)
{

char *tt;

tt=strstr(string,"*.*");
if (tt)
 sprintf(tt,"%s\\*.*",name);
}

compare(char *this, char *that)
{
int first=0,second=0;
if (*this == '*' || strchr(this,'\\'))
    first=1;
if (*that == '*' || strchr(that,'\\'))
    second=1;

if (first && !second)
        return(-1);
if (second && !first)
        return(1);

return(strcmp(this,that));

}



char *basename(char *string)
{

_asm  {
      push      si
      push      di
      cld
      mov        si,string
      mov        di,si
f1:   lodsb
      cmp       al, '\\'
      jnz       f2
      mov       di,si
f2:   or         al,al
      jnz        f1
      cld
      mov       string,di
      pop       di
      pop       si
      }

return(string);
}

char *qualify(char *p)
{
unsigned drive=0,drivenow=0,junk=0;
char *dirnow,*drivedir;
int ok=0;

_dos_getdrive(&drivenow);
dirnow=getcwd(NULL,64);

if (*(p+1) == ':')
  drive=(toupper(*p)-64);
else
  drive=drivenow;


if (*p == 0)
  return(strlwr("*.*"));
if (strcmp(p+1,":")==0)
   {
   strcat(p,"*.*");
   return(p);
   }

_dos_setdrive(drive,&junk);
drivedir=getcwd(NULL,64);
ok=chdir(p);

chdir(drivedir);

_dos_setdrive(drivenow,&junk);
chdir(dirnow);
if (!ok)
{
if (strcmp(strrchr(p,'\\'),"\\") !=0)
    {
    strcat(p,"\\*.*");
    }
else
    {
    strcat(p,"*.*");
    }
}
else
  {
  if (!strstr(p,".*") && strstr(p,"*") && !strstr(p,"*."))
     strcat(p,".*");

  }

return(p);


}


void s_print(struct dta *dtp)
{
struct tm *tptr;
time_t now;

if (dtp->flag & Dir_Mask)
   return;
time(&now);
tptr=localtime(&now);

sprintf(Newname,"%.2d%.2d%.2d%s\.001",tptr->tm_year,tptr->tm_mon+1,tptr->tm_mday,Ext);
sprintf(Archname, "%s\\%s",Archdir,Newname);
while (access(Archname,0) == 0)
{
Counter++;
sprintf(Newname,"%.2d%.2d%.2d%s\.%.3d",tptr->tm_year,tptr->tm_mon+1,tptr->tm_mday,Ext,Counter);
sprintf(Archname, "%s\\%s",Archdir,Newname);
}
sprintf(Cbuf,"COPY %s %s",dtp->name,Archname);
system(Cbuf);

}
 







Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar


Auto FTP Manager


/Dos/ibcopy.html copyright All Rights Reserved

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server






More:


Unix/Linux Consultants

Skills Tests

Guest Post Here











My Favorites

Change Congress