Lisp HUG Maillist Archive

does LispWorks have a function for copying files?


Could you point me to the right function? I couldn't find one in the 
documentation. Or do I need to write my own? If the latter, would a 
loop that calls read-char and write-chare do the job correctly for 
arbitrary files (i.e. nor just text files, but also Excel Word etc)?

     Thanks,

	Mark


-- 
Mark Klein
Principal Research Scientist
Massachusetts Institute of Technology
77 Massachusetts Avenue, NE20-336
Cambridge MA 02139 USA
m_klein@mit.edu
http://ccs.mit.edu/klein/


Re: does LispWorks have a function for copying files?

FWIW, Edi Weitz's CL-FAD (files and directories) includes a generic  
copy-file command as does my metatilities. Both of these libraries  
are ASDF-Installable.


On Nov 14, 2006, at 4:15 PM, Mark Klein wrote:

>
>
> Could you point me to the right function? I couldn't find one in  
> the documentation. Or do I need to write my own? If the latter,  
> would a loop that calls read-char and write-chare do the job  
> correctly for arbitrary files (i.e. nor just text files, but also  
> Excel Word etc)?
>
>     Thanks,
>
> 	Mark
>
>
> -- 
> Mark Klein
> Principal Research Scientist
> Massachusetts Institute of Technology
> 77 Massachusetts Avenue, NE20-336
> Cambridge MA 02139 USA
> m_klein@mit.edu
> http://ccs.mit.edu/klein/
>

--
Gary Warren King, metabang.com
Cell: (413) 885 9127
Fax: (206) 338-4052
gwkkwg on Skype * garethsan on AIM





Re: does LispWorks have a function for copying files?

Mark Klein wrote:

> If the latter, would a loop that calls read-char and write-chare do
> the job correctly for arbitrary files (i.e. nor just text files, but
> also Excel Word etc)?

To be on the safe side, I would use READ-BYTE and WRITE-BYTE and open
the files with element-type (UNSIGNED-BYTE 8).

(And you may get higher performance if you use READ-SEQUENCE and
WRITE-SEQUENCE.  Then again, you may not...)

Arthur Lemmens


Re: does LispWorks have a function for copying files?

Mark Klein wrote:
> Could you point me to the right function? I couldn't find one in the
> documentation. Or do I need to write my own? If the latter, would a
> loop that calls read-char and write-chare do the job correctly for
> arbitrary files (i.e. nor just text files, but also Excel Word etc)?
>
>     Thanks,
>
> Mark

Maybe there's a better way, but I think this should work. It treats the file 
as binary and reads bytes:

(with-open-file (in-str in-filename :direction :input :element-type 
'(unsigned-byte 8))

  (with-open-file (out-str out-filename :direction :output :element-type 
'(unsigned-byte 8))
     (do ((ubyte (read-byte in-str nil) (read-byte in-str nil)))
          ((null ubyte))
        (write-byte ubyte out-str))))

Mitch


Re: does LispWorks have a function for copying files?

Hmm, what about

http://www.cl-http.org:8000/cl-http/lispdoc?package=HTTP&symbol=COPY- 
FILE&type=FUNCTION&apropos=copy%2Bfile

Or  (http::apropos* '(copy file) :http 'function)?
FTP-COPY-FILE [function]: (FROM-URL TO-STREAM &KEY)
WITH-COPY-FILE-ENVIRONMENT [macro]: ((FROM TO STREAM &OPTIONAL (BLOCK- 
NAME (QUOTE COPY-FILE))) &BODY BODY)
FILE-URL-COPY-FILE-TO-HTTP-STREAM [function]: (FILE-URL-OR-PATHNAME  
HTTP-STREAM &KEY CONTENT-TYPE URL ADDITIONAL-HEADERS USER-ID USER-PW)
COPY-FILE [function]: (SOURCE DESTINATION &KEY COPY-MODE REPORT- 
STREAM REQUEST-HEADERS USER-EMAIL-ADDRESS &ALLOW-OTHER-KEYS)
CONDITIONAL-COPY-FILE [function]: (FROM-PATHNAME TO-PATHNAME &KEY  
&ALLOW-OTHER-KEYS)
FILE-URL-COPY-FILE [function]: (FILE-URL-OR-PATHNAME TO-STREAM &KEY  
ELEMENT-TYPE USER-ID USER-PW)

On Nov 14, 2006, at 4:15 PM, Mark Klein wrote:
>
>
> Could you point me to the right function? I couldn't find one in  
> the documentation. Or do I need to write my own? If the latter,  
> would a loop that calls read-char and write-chare do the job  
> correctly for arbitrary files (i.e. nor just text files, but also  
> Excel Word etc)?
>
>     Thanks,
>
> 	Mark
>
>
> -- 
> Mark Klein
> Principal Research Scientist
> Massachusetts Institute of Technology
> 77 Massachusetts Avenue, NE20-336
> Cambridge MA 02139 USA
> m_klein@mit.edu
> http://ccs.mit.edu/klein/
>


On Nov 14, 2006, at 4:15 PM, Mark Klein wrote:

>
>
> Could you point me to the right function? I couldn't find one in  
> the documentation. Or do I need to write my own? If the latter,  
> would a loop that calls read-char and write-chare do the job  
> correctly for arbitrary files (i.e. nor just text files, but also  
> Excel Word etc)?
>
>     Thanks,
>
> 	Mark
>
>
> -- 
> Mark Klein
> Principal Research Scientist
> Massachusetts Institute of Technology
> 77 Massachusetts Avenue, NE20-336
> Cambridge MA 02139 USA
> m_klein@mit.edu
> http://ccs.mit.edu/klein/
>


Updated at: 2020-12-10 08:47 UTC