I want make a package to add a function to Mathematica that reads all excel files is the working directory that is set after the package is loaded.
BeginPackage["Reader`"]
f::usage="f[] returns data from excel file"
Begin["`Private`"]
f[]:=Module[{files},
files = FileNames["*.csv",Directory[]];
data = Import[#]& /@ files;];
End[]
EndPackage[]
What is happening
Currently, if I load the package, it immediate reads any excel files in default folder.
<<Reader`
Trouble -- excel files in default folder get read
SetDirectory["somewhere"]
read=f[]
(*Result!*)
What I want
I want to load the package without reading in the excel file, so I can change the working directory before I call f
.
<<Reader
Package is loaded but no excel files are read
SetDirectory["somewhere"]
read = f[]
(*Result!*)
Is possible to do what I want or do I need to define the function in a different way?
f
is set delayed, after<<Reader`
nothing will be imported. Have I missed something? $\endgroup$ – Kuba♦ Dec 5 '15 at 19:35