Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Moving files/directories in Common Lisp

Name: Anonymous 2009-12-20 14:45

What is the best way to do it?

I know there is rename-file, but it doesn't work across partitions and moving from one directory to another isn't portable either it seems. It's also only for files.

Google didn't help me. The closest thing I found was http://common-lisp.net/project/osicat/ which adds some nice things related to files/directories, among others, but not what I'm looking for.

I could only come up with reading from a file, writing it somewhere else and deleting the original, but that would be a really shitty way to do it for obvious reasons and even worse for directory trees.

Name: Anonymous 2009-12-20 14:48

If you think that's depressing, try looking at (rnrs files).

Name: Anonymous 2009-12-20 14:51

There's a good reason it's hard to do. It's because you shouldn't do it.
Lisp dialects are meant to be used by the elite as a way to express elegant algorithms, not for pedestrian labor such as handling files or making interactive web applications.

Name: Anonymous 2009-12-20 14:58

>>2
They can't be serious.
>>3
I thought that's Scheme, whereas Common Lisp was made to be actually useful.
So is "Practical Common Lisp" a lie?

Name: Anonymous 2009-12-20 15:27

>>4
Read "Practical Anus Haxing"

Name: Anonymous 2009-12-20 15:37

Aren't these the problems that the common lisp cookbook was made for

>>4
I thought that's Scheme, whereas Common Lisp was made to be actually useful.
>:¬

Name: Ctard 2009-12-20 16:04

Enjoy your languages that disable you from doing the most basic fucking things.

Name: Anonymous 2009-12-20 16:08

>>7
Confusing libraries and languages, I expected better from a C user.

Name: Anonymous 2009-12-20 16:11

>>7
QUESTION! Can you write an O(n) fibs in one line! Didn't think so!

Name: Anonymous 2009-12-20 16:29

>>9
Yes.

Name: Anonymous 2009-12-20 18:41

>>9
Unlike FIOC, C has no concept of lines!!

int main(void){puts("enterprise!");return 0;}

Name: Anonymous 2009-12-20 20:15

>>11
[quote]main(void)[/quote]
I came

Name: Anonymous 2009-12-20 22:31

>>12
Oh no!! Your [sup]BB[/sup][sub]CODE[/sub]!

Name: Anonymous 2009-12-20 22:32

>>13
This is TERRIBLE!

Name: Anonymous 2009-12-20 23:17

>>1
RENAME-FILE works perfectly in most major implementations, even with string path designators. Why do you care as long as it's de-facto portable?

Name: Anonymous 2009-12-21 1:42

>>3
8/10

Name: Anonymous 2009-12-21 11:44

>>15
It doesn't work across partitions (tried with sbcl). Well, it seems like there is no better way to do it.

I guess I'll just do a rename-file first and if an error arises handle it by copying the file contents manually.

Name: Anonymous 2009-12-21 12:14

>>17
You're right, just tried it myself, won't work on Win32 at least.
(On Win32, it thunks down to a call of the MoveFile API, which clearly specifies: The one caveat is that the MoveFile function will fail on directory moves when the destination is on a different volume.)
I can see a few possible solutions to this. You would have to copy the directory and delete it, if the renaming fails(or is done across drives), but this would mean that date and permissions won't be copied if you use just CL's functions to do this. You could just use the FFI, and use the OS-specific functions which copy permissions/date in that case. (You have not specified, if you wish the permissions/date/attributes to be preserved or not? If you don't, it should be doable portably, otherwise, you would have to write per-platform specific code).

Name: >>18 2009-12-21 12:20

While I prefer SBCL myself, here's yet another non-portable way to do it in CLISP:
http://clisp.cons.org/impnotes/dir-func.html

Name: anonymous 2010-02-09 16:44

i've got the same problem
looks like the only way is to perform an alien call

Name: Anonymous 2010-02-09 17:02

>>7
Oh, you seem to know C. Could you please explain to me, how should I move files/directories in C?

Name: Anonymous 2010-02-09 17:12

It's perfectly logical, you guys: obviously moving a file across partitions will require copying its contents, but even worse, you have no way of knowing, a priori, whether a given directory is on the same partition as another (mount points, yo) (although implementations should probably provide a system-dependent way to check); to ensure consistent behavior, the standard did not attempt to make rename-file do all these things. I believe Plan 9 has the same “problem”.

Name: Anonymous 2010-02-09 20:57

Why can't someone just create good bindings for some of the POSIX libs.

Name: Anonymous 2010-02-09 23:49

>>23
Most Lisps prefers to act like some incompatible Lisp Machine black box and not like a program running on your actual OS.
For the same reason running multiple Lisp programs gives you a huge overhead (no sharing memory, oh joy!) unless you load it into the same Lisp image which is downright insanity so no one does it. Just Imagine every program loading extra copies of all linked libraries into memory. That's what running multiple Lisp programs is like.

I wish I was joking.

Name: Anonymous 2010-02-09 23:53

>>9
QUESTION! Can you write an O(1) fibs in one line! Didn't think so!

Name: Anonymous 2010-02-10 1:09

>>24
unless you load it into the same Lisp image which is downright insanity so no one does it.
Except Emacs users? Only reason no one does it with CL is because nobody has multiple CL apps to use.

Name: Anonymous 2010-02-10 2:05

>>24
You wish you were joking.

Name: Anonymous 2010-02-10 5:20

>>27
The subjunctive mood is dead!

Name: !iN.MY.aRMs 2010-02-10 5:30

jast use FORTRAN77

Name: Anonymous 2010-02-10 9:01

>>28
If I were king, it wouldn't be!

Name: Anonymous 2010-02-10 9:59

What's the POSIX call for copying a file? I want it to take advantage of copy-on-write filesystem behavior where possible, and to preserve metadata.

Name: Anonymous 2010-02-10 10:42

>>31
I may be wrong, but doesn't this sound like way too high level task to be implemented as a system call? If so, you'll probably have to write your own using neat POSIX QUALITY read()/write().

Name: Anonymous 2010-02-12 15:40

You see, things like this are the reason people can't use Common Lisp even if they wanted to.

Name: Anonymous 2010-02-12 15:59

>>33
Fuck, you're right. I was just about to embark on an epic program but I can't copy files. FUUUUU

Name: Anonymous 2010-02-12 16:08

>>33
That's silly, the problem exists in plenty of other languages. Above all, it's platform specific. If you can't write some 10 lines of code to deal with platform specific crap, then you shouldn't be programming at all. I have no problem isolating my portable from non-portable code, especially with the useful sharp-plus/minus reader macro. In the end, I'd have to write roughly the same amount of code in C, if not more to perform this task in a manner that it'd work correctly on both Win32 and *nix.

Name: Anonymous 2010-12-06 9:09

Back to /b/, ``GNAA Faggot''

Don't change these.
Name: Email:
Entire Thread Thread List