directory

Started by newdep, March 23, 2005, 06:09:00 AM

Previous topic - Next topic

newdep

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
-- (define? (Cornflakes))

Lutz

#1
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

newdep

#2
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
-- (define? (Cornflakes))

newdep

#3
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.
-- (define? (Cornflakes))

Lutz

#4
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

newdep

#5
!!! APPLAUSE !!!  Guru in progress ;-)



Thanks !



Norman.
-- (define? (Cornflakes))

newdep

#6
Btw... Thats one hell off an CPU eater ;-) My windows machine goes crazy

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



Norman.
-- (define? (Cornflakes))

Lutz

#7
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