[jamming] Problems with listing files in directories
Alen Ladavac
alenl-ml at croteam.com
Tue May 23 05:13:50 PDT 2006
Not sure exactly what could be wrong with this version. Didn't the
original version I posted work ok?
But clearly the comment:
> # filter so that only real files are included (skip current dir, parent
> dir and all other dirs)
is wrong, as you never test against inclusion of subdirs. Also note
that [ GLOB $(1) : * ] has a quirk that if $(1) is a file, it will
return that file.
HTH,
Alen
Klaus 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
--
Alen
More information about the jamming
mailing list