MathGroup Archive 2009

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

Search the Archive

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

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*)
 FindList[myFileNames[[i]], "top secret"] // Print,
 {i, 1, Length[myFileNames]}

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

 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>
> 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: StringJoin with ToString
  • 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: release memory