Alexander Burger <a...@software-lab.de> writes: Hi Alex,
>> Is there a way to make 'out' write directories too? > > No, 'out' just creates or opens a file for writing. ok >> Or do I have to use something like >> >> ,-------------------------- >> | (call 'mkdir "/new/dir/") >> `-------------------------- > > Yes. But this works only if "/new/" already exists. If "/new/" is also > missing, you can create the complete path with > > (call 'mkdir "-p" "/new/dir/") > > (BTW, do you really want to write to the root directory "/"?) yes, I figured that "-p" out too after an error message, and no, the "/new/dir/" was just an example, has nothing to do with reality. >> ,----------------------- >> | (call 'cd "/new/dir/") >> `----------------------- >> >> then >> >> ,------------------------------------------------ >> | (out "newfile" (in "a" (echo)) (in "b" (echo))) | >> `------------------------------------------------ > > No. 'cd' is a shell builtin, and cannot be used wit 'call'. then I know why it didn't work as expected... > There are two lisp functions for that, 'cd' and 'chdir' > > (cd "/new/dir/") > > or > > (chdir "/new/dir/" .. <body> ..) > > The difference is that 'chdir' executes the body and then restores the > original working directory (also if an exception (throw) occurs within > the body). > > (chdir "/new/dir/" (out "newfile" ..)) I see ... > But in general I would be careful with 'cd' and 'chdir', as it modifies > the working directory of the whole process. For example, "a" and "b" > above will not be found (as the directory is new), and you must use > "../../a" or something like that. > > Better is usually to call > > (let Dir "/new/dir/" > (call 'mkdir "-p" Dir) > (out (pack Dir "newfile") (in "a" ...)) ) thats probably exactly what I wanted, thanks. -- cheers, Thorsten -- UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe