newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newdep on March 23, 2005, 06:09:00 AM

Title: directory
Post by: newdep on March 23, 2005, 06:09:00 AM
Hi Lutz,



Small question on a small problem..?

(on windows and linux)





(directory "/") returns a list of all files in "/"  * this works fine *



(directory? "/") returns true * also fine *





(filter directory? (directory "/") * not so fine, returns () *





So where is the problem ? Is it with 'Filter ? because the above is 100%

according the syntax expectation..



BUT! this works ->



(change-dir "/")

(filter directory? (directory "/"))



* Where "/" is the current directory, if you leave "/" out it also works

but it does not work without change-dir *





Where is the misintepretation?



regards, Norman
Title:
Post by: Lutz on March 23, 2005, 06:36:48 AM
Everything is fine :), in:



(filter directory? (directory "/") )



the term:



(directory "/")



returns a list of all files in "/" but without the directory prefix. The 'directory?' function then checks i.e. "WINDOWS", which is a directory but not in the current directory. For that reason it works when you do a 'change-dir' to "/" first or prepend a "/" to "WINDOWS" to get "/WINDOWS"



(directory? "WINDOWS") => nil

(directory? "/WINDOWS") => true



Try this, and it works without 'change-dir'



(filter directory? (map (fn (f) (append "/" f)) (directory "/")))



Lutz
Title:
Post by: newdep on March 23, 2005, 06:43:24 AM
Oke yes thats what im doing currently too..though it makes life not easier

when its upto the next problem ->



Try to make a MAP of all the directory Names on your local harddisk and

store them in a nested LIST as a tree ;-)



Thats partly the problem im facing regarding the topic on 'Depth' :-)



Regards, Norman
Title:
Post by: newdep on March 23, 2005, 06:47:43 AM
I need to take care of several counters regarding the depth

of the directory structure...



(1) Current directory in the tree

(2) amount of directorys in the current directory

(3) the depth inside the main directory tree



Im trying to make 1 simple lambda that can cover this nested problem ;-)



(I think thats a nice Brain teaser ;-)



Regards, Norman.
Title:
Post by: Lutz on March 23, 2005, 07:53:07 AM
Try this one:

(define (show-tree dir counter)
 (dolist (nde (directory dir))
   (if (and (directory? (append dir "/" nde)) (!= nde ".") (!= nde ".."))
        (show-tree (append dir "/" nde) (+ counter 1))
        (println counter ": "(append dir "/" nde)))))

> (show-tree "c:/Borland" 0)
0: c:/Borland/.
0: c:/Borland/..
1: c:/Borland/BCC55/.
1: c:/Borland/BCC55/..
2: c:/Borland/BCC55/Bin/.
2: c:/Borland/BCC55/Bin/..
2: c:/Borland/BCC55/Bin/bcc32.cfg
2: c:/Borland/BCC55/Bin/bcc32.exe


Works on both Linux and Win32



Lutz
Title:
Post by: newdep on March 23, 2005, 09:50:59 AM
!!! APPLAUSE !!!  Guru in progress ;-)



Thanks !



Norman.
Title:
Post by: newdep on March 23, 2005, 10:56:33 AM
Btw... Thats one hell off an CPU eater ;-) My windows machine goes crazy

when I run that one from the newlisp console...



Norman.
Title:
Post by: Lutz on March 23, 2005, 01:15:06 PM
This is due to the huge amount of text output filling up the console display buffer in newLISP-tk which is of many-megabyte size.



When running show-tree in a shell window as a command-line utility memory requirements are costant about 1Mbyte on my machine and it does about 5,000 files per second.



Lutz