farris@marlin.NOSC.MIL (Russell H. Farris) (06/27/88)
Can anyone direct me to a utility that reads the name of an MSDOS file and then inserts the name at the top of the file? Thanks, Russ Farris (farris@marlin.nosc.mil)
wnp@dcs.UUCP (Wolf N. Paul) (06/28/88)
In article <1045@marlin.NOSC.MIL> farris@marlin.NOSC.MIL (Russell H. Farris) writes: > >Can anyone direct me to a utility that reads the name of an MSDOS >file and then inserts the name at the top of the file? Thanks, > >Russ Farris (farris@marlin.nosc.mil) I'm not sure that this can be done EXCEPT BY COPYING the entire file. That method is trivial: ===================== /* As shown here, works only for files in the current directory. To generalize, a function "dirname" would be needed to extract the directory name from each filename, as rename() in MSDOS ususally does not handle renames across directories very gracefully. */ #include <stdio.h> main(ac, av) int ac; char *av[]; { FILE *ifp, *ofp, *fopen(); static char *template="myXXXXXX"; char *tmpname; char c; int i=1; while ( i != ac ) { tmpname=mktemp(template); /* I think MSC has this */ ifp=fopen(av[i],"rb"); /* optionally add error checking here */ ofp=fopen(tmpname, "wb"); /* optionally add error checking here */ fprintf(ofp, "%s", av[i]); /* optionally "%s\n" or whatever */ while ( (c=getc(ifp)) != EOF ) putc(c, ofp); /* this could be done more efficiently */ fclose(ifp); fclose(ofp); unlink(av[i]); /* use whatever you have to delete */ rename(tmpname, av[i]); /* and rename or move files */ } } =================== Hope this helps. Wolf Paul -- Wolf N. Paul * 3387 Sam Rayburn Run * Carrollton TX 75007 * (214) 306-9101 UUCP: killer!dcs!wnp ESL: 62832882 DOMAIN: wnp@dcs.UUCP TLX: 910-380-0585 EES PLANO UD
tj@mks.UUCP (T. J. Thompson) (07/09/88)
In article <1045@marlin.NOSC.MIL>, farris@marlin.NOSC.MIL (Russell H. Farris) writes: > > Can anyone direct me to a utility that reads the name of an MSDOS > file and then inserts the name at the top of the file? Thanks, > # # Shell script to put file name on first line of each argument file for f in "$@" do ed - "$f" <<-! 0a $f . w q done Shell?? you say? ed??? MKS Toolkit is the answer. Wasn't that easy? -- ll // // ,'/~~\' T. J. Thompson uunet!watmath!mks!tj /ll/// //l' `\\\ Mortice Kern Systems Inc. (519) 884-2251 / l //_// ll\___/ 35 King St. N., Waterloo, Ont., Can. N2J 2W9 O_/ long time(); /* know C */