Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: passing an array variable as a file name string to FindList

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98282] Re: passing an array variable as a file name string to FindList
  • From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
  • Date: Fri, 3 Apr 2009 20:14:44 -0500 (EST)
  • References: <gr4jg8$a6g$1@smc.vnet.net>

Hi Venkatesh,

There must be many ways to do this. I'll provide you with three
examples, two of them the Fortran way and one the Mathematica way
(don't worry, they all work in Mathematica).

myFileNames = FileNames[];

(* Classis Fortran style; long; i is an index in the list*)
Do[
 FindList[myFileNames[[i]], "top secret"] // Print,
 {i, 1, Length[myFileNames]}
 ]


(*Fortran style; slightly shorter; i itself gets the successive values
of the list*)

Do[
 FindList[i, "top secret"] // Print,
 {i, myFileNames}
 ]

(*Mathematica functional programming style, /@ is shorthand infix
notation for Map; # and & are used to make a pure function*)

FindList[#, "top secret"] & /@ myFileNames

Cheers -- Sjoerd

On Apr 3, 11:05 am, Venkatesh Ramakrishnan <venk... at tifr.res.in>
wrote:
> Hi Everybody
>
>  I have this problem for which I have to write a code -
>
>  1. There is a directory that contains around 30,000 text files.
> 2. I wish to read each one of them and extract some information.
>
>  Now,
>
>  Flatten[Table[FileNames[]]]
>
>  will give me all the file names in a table.
>
>  So,
>
>  An array variable with the subscript that contains the loop counter
> will
>  give me the filenames one by one.
>
>  The question is, how do I pass the array variable as a String argument
>  to functions like -
>
>  FindList[]
>  ReadList[]
>
>  and other text file manipulation commands?
>
>  If anybody can shed some light on this, I would be very thankful.
>
>  With best regards
>  Venkatesh



  • Prev by Date: Re: Styling the selected Tab's label in TabView
  • Next by Date: Re: Graphics and DisplayFunction
  • Previous by thread: Re: passing an array variable as a file name string to FindList
  • Next by thread: Re: passing an array variable as a file name string to FindList