[jamming] Problems with listing files in directories
rafael baptista
rafael at oroboro.com
Tue May 23 06:39:28 PDT 2006
I have my own version of Jam called KJam. The KJam language is a little
different, and somewhat more powerful than Jam. It has native
expressions to list all the files in a given directory:
directory = src/* ;
files = $(directory:M) ;
This would list all the files in the src subdirectory. You can also do
it without the intermediate $(directory) variable like this:
files = @(src/*:M) ;
To get just the .c files:
file = @(src/*:MI="\.c$") ;
The project can be found at
http://www.oroboro.com/kjam
-Rafael
Klaus Meier wrote:
>I'm searching now recursively in the subdirectories for c-files.
>But the problem is that there are always two entries for one file in the
>resulting list.
>Here's the code:
>
># [ ListFilesinDir directory ]
># Lists all Files, also recursively in a given directory
># e.g.: subdirs = [ ListFilesinDir . ] ;
>#
># list all files in the directory and subdirectories
>#
>#---------------------------------------------------------------
>
>rule ListFilesinDir {
>
> local _f = ;
> local _result = ;
> local _temp ;
> # initially use the files in the current directory
> local _files = [ GLOB $(1) : * ] ;
>
>
> # filter so that only real files are included (skip current dir, parent
>dir and all other dirs)
> for _f in $(_files)
> {
> if $(_f:BS) != . && $(_f:BS) != .. && [ MATCH "($(2))" : $(_f) ]
> {
> _result += $(_f) ;
> }
> }
>
> local _subdirlist = [ ListDirs $(1) ] ;
>
> # for each subdir/file
> for _subdir in $(_subdirlist)
> {
> # recurse into it
> _result += [ ListFilesinDir $(_subdir) : $(2) ] ;
> }
>
> # return the resulting list
> return $(_result) ;
>}
>
>
>c_files = [ ListFilesinDir . : [a-z]*[.][c] ] ;
>
>The output of c_files is the following:
>
>c-files = .\hello.cpp .\StdAfx.cpp .\lib_p1\source\mytools.cpp
>.\lib_p1\source\mytools.cpp
>
>The ouput of "dir /s /b" is the following:
>D:\Programming\hello>dir /s /b
>D:\Programming\hello\.svn
>D:\Programming\hello\Debug
>D:\Programming\hello\exe_1
>D:\Programming\hello\exe_2
>D:\Programming\hello\hello.cpp
>D:\Programming\hello\hello.dsp
>D:\Programming\hello\hello.dsw
>D:\Programming\hello\hello.ncb
>D:\Programming\hello\hello.opt
>D:\Programming\hello\hello.plg
>D:\Programming\hello\jam.exe
>D:\Programming\hello\Jambase
>D:\Programming\hello\Jamfile
>D:\Programming\hello\jam_log.txt
>D:\Programming\hello\lib_p1
>D:\Programming\hello\lib_p2
>D:\Programming\hello\log.txt
>D:\Programming\hello\ReadMe.txt
>D:\Programming\hello\StdAfx.cpp
>D:\Programming\hello\StdAfx.h
>D:\Programming\hello\windows.jam
>D:\Programming\hello\.svn\.svn-test
>D:\Programming\hello\lib_p1\debug
>D:\Programming\hello\lib_p1\source
>D:\Programming\hello\lib_p1\source\mytools.cpp
>D:\Programming\hello\lib_p1\source\mytools.h
>
>Is there any suggestion of how I can solve this problem??
>
>Best regards
>
>Winston
>
>_________________________________________________________________
>Sie suchen E-Mails, Dokumente oder Fotos? Die neue MSN Suche Toolbar mit
>Windows-Desktopsuche liefert in sekundenschnelle Ergebnisse. Jetzt neu!
>http://desktop.msn.de/ Jetzt gratis downloaden!
>_______________________________________________
>jamming mailing list - jamming at perforce.com
>http://maillist.perforce.com/mailman/listinfo/jamming
>
>
>
More information about the jamming
mailing list