[Swift-devel] Q of traversing all files in one directory

Mihael Hategan hategan at mcs.anl.gov
Mon Dec 29 13:15:51 CST 2008


On Mon, 2008-12-29 at 13:05 -0600, Zhao Zhang wrote:
> Hi, All
> 
> Sorry to send out a Q in Holiday time.
> My question is about Chapter 3.7 of swift tutorial, the foreach 
> statement and regexp_mapper.
> 
> In the following code example, all input files are listed in the string.
> 
> string inputNames = "one.txt two.txt three.txt";  
>   
> messagefile inputfiles[] <fixed_array_mapper; files=inputNames>;    
>   
> foreach f in inputfiles {  
>   countfile c <regexp_mapper;  
>                source=@f,  
>                match="(.*)txt",  
>                transform="\\1count">;  
>   c = countwords(f);  
> }
> 
> 
> How can I say that
> 
> foreach file in a directory {
>    outfile = app(file)
> }
> 
> In swift ?

You use the filesystem mapper instead.

messagefile inputfiles[] <filesys_mapper; location="some/dir">;

(refer to the docs for the full set of parameters for that mapper).




More information about the Swift-devel mailing list