Use of FileNameSetter

Hi all,

I´m trying to build a little function that lets me choose a file from a directory an returns me the filename, so I can then read in the contents of this file. FileNameSetter does this job, but I have difficulties to integrate this function in a whole module. I tried a lot, but it seem that I simply have not the right understanding, so I´m stuck in the enclosed example notebook. Can someone give me a hint how I can manage this.

readFile[liste_] := Module[{listLoc = “”, temp},

temp = {FileNameSetter[Dynamic @ f,], Dynamic @ f};

 listLoc = Import[f, "Words"]   (* not working :-( *)

]

Greetings

Mike

choose a file from a directory an returns me the filename, so I can then read in the contents of this file

getContent[] := Module[{fileName, content = {}},
  fileName = SystemDialogInput["FileOpen"];
  If[fileName =!= $Canceled, content = Import[fileName]];
  content
  ]

called as

content = getContent[]

Hi Nasser,

and thanks a lot, this helps me out :slight_smile: I´ve really been stuck in this FileNameSetter-world, which was simply the wrong way.

Thank you!

Mike