Xref: utzoo comp.sys.ibm.pc:16781 comp.binaries.ibm.pc.d:479 Path: utzoo!attcan!uunet!lll-winken!lll-tis!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!purdue!bu-cs!bloom-beacon!mit-eddie!killer!dcs!wnp From: wnp@dcs.UUCP (Wolf N. Paul) Newsgroups: comp.sys.ibm.pc,comp.binaries.ibm.pc.d Subject: Re: UTILITY TO PUT FILENAME AT TOP OF FILE Keywords: filenames Message-ID: <128@dcs.UUCP> Date: 28 Jun 88 12:16:45 GMT References: <1045@marlin.NOSC.MIL> Reply-To: wnp@dcs.UUCP (Wolf N. Paul) Organization: DCS, Dallas, Texas Lines: 51 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. */ #includemain(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