Path: ...!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp Subject: Re: Is there an efficient way to get file length w/o reading file? Date: Mon, 2 Sep 2024 19:58:56 -0000 (UTC) Organization: A noiseless patient Spider Lines: 26 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Mon, 02 Sep 2024 21:58:57 +0200 (CEST) Injection-Info: dont-email.me; posting-host="a435632fcbba468531e98d5e4c12abf8"; logging-data="3134670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FYpz2SAYHWHcoqTH5AROg" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:qd2eN3lI3k5ydkDZJHNbptHtMww= Bytes: 1803 Pascal Bourguignon wrote: > > > An intelligent implementation could avoid reading the file. > > > But otherwise, the answer is that it's not possible portably. > > > Drop down to the POSIX API. > > > > How does one do that? Is there an example somewhere? > > (defun file-length-in-bytes (file) > ;; Note the "EXT" implementation specific package. > (with-open-stream (in (ext:run-program "/bin/ls" > :arguments (list "-l" (namestring file)) > :output :stream)) > (read in)(read in)(read in)(read in)(read in))) > > Alternatively, one could use FFI: > > (defun file-length-in-bytes (file) > (multiple-value-bind (res stat) (linux:stat (namestring file)) > (linux:|stat-st_size| stat))) Gauche Scheme: (use file.util) (file-size "data.txt")