creating a list from directory and file-info

Started by SHX, April 05, 2007, 10:10:49 AM

Previous topic - Next topic

SHX

Hello,



I am trying to create a list with filefolder names fro the directory commandd and the file-info information for each member of the list.



I have the output in 2 lists and I am trying to use a map with a push to combine them. However the push returns just the item that was pushed.



If someone can help with an example of how create a list of files and there info  and also how can values from one list be pushed into a list of lists.



Thanks,



I hope I was understandable.



Steven

cormullion

#1
I'm not sure you need two lists - you can get file-info for every item in a list produced by directory by mapping a function over the list:


(set 'dirlist (directory "/"))

(map (fn (f) (println f "t" (file-info f))) dirlist)

;->
..Developer (476 16893 0 0 80 1175695159 1175694126 1175694126)
etc        (3162 41453 0 0 80 1127373182 1127373182 1137361024)
Library (1870 17405 0 0 80 1175791160 1174234983 1174234983)
mach (603684 41453 0 0 80 1174913732 1174913732 1174913732)
..


If you have two lists that match, you can combine them neatly:


(set 'dirlist (directory "/"))
(set 'infolist (map (fn (f) (file-info f)) dirlist))
(transpose (list dirlist infolist))

or

(map list dirlist infolist)

Lutz

#2
... and to combine two lists you would do the following:



> (set 'list-1 '(a b c d))
(a b c d)
> (set 'list-2 '(1 2 3 4))
(1 2 3 4)
> (map list list-1 list-2)
((a 1) (b 2) (c 3) (d 4))
>


Lutz

SHX

#3
Lutz and cormullion, thanks alot for your help. I am new at this but starting to get the hang of it and really appreciate the power it has. Thanks Lutz for such a great product.



Steven

SHX

#4
Hi,



When I do
(map list list-1 list-2)



I get the following.
Quote("Demo.lsp" (1408 33206 2 0 0 1177559281 1174002288 1174002288))

 ("Drag.lsp" (1152 33206 2 0 0 1177559281 1174002288 1174002288))
 


How can I make it that it each file name and it's info be in one list like the following.


Quote(("Demo.lsp" 1408 33206 2 0 0 1177559281 1174002288 1174002288)

 ("Drag.lsp" 1152 33206 2 0 0 1177559281 1174002288 1174002288))


 


thanks



Steven

cormullion

#5
I think you want to use "cons" rather than "list" here.


(set 'file-name-list (directory "/"))
(set 'file-info-list (map file-info file-name-list))
(map cons file-name-list file-info-list)

( ("Applications" 3808 16893 0 0 80 1177793256 1177531823 1177531823)
 ("Applications (Mac OS 9)" 578 16895 0 501 80 1177793345 1175184313
  1175184313)
...