home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 168.img / ACAD3.ZIP / FCOPY.LSP < prev    next >
Lisp/Scheme  |  1988-07-26  |  1KB  |  25 lines

  1. ;  This is a programming example.
  2.  
  3. ;  This program takes two ASCII files as arguments, and copies the first   
  4. ;  file into the second.  If the first file does not exist, an error message 
  5. ;  is displayed; however, if the second file does not exist, it is created.
  6. ;  Note that if the second file exists, its data will be overwritten.
  7. ;  Usage: (fcopy "infile.ext" "outfile.ext")
  8.  
  9. (defun fcopy (in out / ifp ofp l)
  10.    (cond ((null (setq ifp (open in "r")))       ; try to open in for reading
  11.                 (princ "Can't open ")           ; if nil print error message
  12.                 (princ in)
  13.                 (princ " for reading."))
  14.         (if ifp (progn
  15.                 (setq ofp (open out "w"))       ; else open out for writing
  16.                 (while (setq l (read-line ifp)) ; read each line from in
  17.                    (write-line l ofp)           ; and write it to out
  18.                 )
  19.                 (close ofp)                     ; close both files
  20.                 (close ifp))
  21.         )
  22.    )
  23.    (princ)
  24. )
  25.