Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10571 > unrolled thread

Default path for opening files

Started bynanobio9 <kuokan.liang@gmail.com>
First post2012-06-21 09:15 +0000
Last post2012-07-01 06:13 +0000
Articles 10 — 6 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Default path for opening files nanobio9 <kuokan.liang@gmail.com> - 2012-06-21 09:15 +0000
    Re: Default path for opening files Helen Read <readhpr@gmail.com> - 2012-06-22 07:02 +0000
      Re: Default path for opening files nanobio9 <kuokan.liang@gmail.com> - 2012-06-23 08:27 +0000
        Re: Default path for opening files Dominik Hezel <sendme2000@me.com> - 2012-06-26 08:48 +0000
    Re: Default path for opening files "E. Martín-Serrano" <eMartinSerrano@telefonica.net> - 2012-06-22 09:15 +0000
    Re: Default path for opening files David Bailey <dave@removedbailey.co.uk> - 2012-06-23 08:22 +0000
    Re: Default path for opening files "E. Martín-Serrano" <eMartinSerrano@telefonica.net> - 2012-06-24 08:22 +0000
    Re: Default path for opening files awnl <awnl@gmx-topmail.de> - 2012-06-25 08:02 +0000
    Re: Default path for opening files "E. Martín-Serrano" <eMartinSerrano@telefonica.net> - 2012-06-26 08:47 +0000
    Re: Default path for opening files nanobio9 <kuokan.liang@gmail.com> - 2012-07-01 06:13 +0000

#10571 — Default path for opening files

Fromnanobio9 <kuokan.liang@gmail.com>
Date2012-06-21 09:15 +0000
SubjectDefault path for opening files
Message-ID<jruonq$fgs$1@smc.vnet.net>
Dear Mathematicans,

Whenever I tried to open a file from my Mathematica directory (with
rather deep structure), I have to start with "~/Documents/" (I am
using Mac). I searched the help and I found that this directory is
coded in the variable "$UserDocumentsDirectory". OK. So I tried to set
this variable to the root of my Mathematica directory, but I found it
protected. Then I setup my local "init.m" file. I unprotect it, set
it, and protect it, in the init.m file. (This is another story though.
I searched the web for half a day and I do not see any example or
instruction, official or by other users, on how people can compose
their own init.m file.) However, nothing is changed.

When my data files grow in number, I decided that I should use the
"FileNameSetter" interface in my NB to pick the file on the fly. That
way I do not have to modify the code ( filename=xxxx ...., blablabla )
for each datafile. However, I found the same problem. In the
"FileNameSetter" function, there is not an option to set the default
starting path. (Or I am just too stupid to use electronic
documentation so that I do not find the solution?) Everything starts
with "~/Documents", although since the second time the directory tree
will be expanded like what I saw the previous time (this is the case
in Mac. I did not try under Windows or Linux).

Is there any smarter way to do this?  Look forward to your helpful
comments.

KKL

[toc] | [next] | [standalone]


#10587

FromHelen Read <readhpr@gmail.com>
Date2012-06-22 07:02 +0000
Message-ID<js15a9$kf3$1@smc.vnet.net>
In reply to#10571
You can manually set the working directory to anything you like with 
SetDirectory["full path here"]


You can also find the path to the directory your current working 
notebook lives in with NotebookDirectory[]. So to set the directory to 
the place where your notebook lives, just do this:

SetDirectory[NotebookDirectory[]]

If I am importing / exporting things from a Mathematica notebook, I'll 
put that at the top of the notebook, usually in an initialization cell 
so the directory is set automatically when I open up the file.

Helen Read
University of Vermont



On 6/21/2012 5:15 AM, nanobio9 wrote:
> Dear Mathematicans,
>
> Whenever I tried to open a file from my Mathematica directory (with
> rather deep structure), I have to start with "~/Documents/" (I am
> using Mac). I searched the help and I found that this directory is
> coded in the variable "$UserDocumentsDirectory". OK. So I tried to set
> this variable to the root of my Mathematica directory, but I found it
> protected. Then I setup my local "init.m" file. I unprotect it, set
> it, and protect it, in the init.m file. (This is another story though.
> I searched the web for half a day and I do not see any example or
> instruction, official or by other users, on how people can compose
> their own init.m file.) However, nothing is changed.
>
> When my data files grow in number, I decided that I should use the
> "FileNameSetter" interface in my NB to pick the file on the fly. That
> way I do not have to modify the code ( filename=xxxx ...., blablabla )
> for each datafile. However, I found the same problem. In the
> "FileNameSetter" function, there is not an option to set the default
> starting path. (Or I am just too stupid to use electronic
> documentation so that I do not find the solution?) Everything starts
> with "~/Documents", although since the second time the directory tree
> will be expanded like what I saw the previous time (this is the case
> in Mac. I did not try under Windows or Linux).
>
> Is there any smarter way to do this?  Look forward to your helpful
> comments.
>
> KKL
>



[toc] | [prev] | [next] | [standalone]


#10613

Fromnanobio9 <kuokan.liang@gmail.com>
Date2012-06-23 08:27 +0000
Message-ID<js3ulv$11c$1@smc.vnet.net>
In reply to#10587
Hi, Helen,

Thanks for the tip. The code I used was very simple. It was copied
from the help file of FileNameSetter:
{FileNameSetter[Dynamic[admittanceFile], "Open", {"mfile" ->
{"*.m"}}], Dynamic[admittanceFile]}

I have hundreds of .m files recording simulation output, organized in
a nested directory. I want the data analysis program to always start
looking for files from the root of this output data directory. I tried
the "SetDirectory" stuff. It helps if one uses commands to save or
load files, indeed, but it does not help 'FileNameSetter' to find the
location, though. That's what I wanted to ask. I think Wolfram
research put FileNameSetter there hoping people make use of it. If
that's true, it has to be more useful.

Thanks again and best regards.
KKL


> You can manually set the working directory to anything you like with
> SetDirectory["full path here"]
>
> You can also find the path to the directory your current working
> notebook lives in with NotebookDirectory[]. So to set the directory to
> the place where your notebook lives, just do this:
>
> SetDirectory[NotebookDirectory[]]
>
> If I am importing / exporting things from a Mathematica notebook, I'll
> put that at the top of the notebook, usually in an initialization cell
> so the directory is set automatically when I open up the file.
>
> Helen Read
> University of Vermont
>
> On 6/21/2012 5:15 AM, nanobio9 wrote:
>
>

[toc] | [prev] | [next] | [standalone]


#10640

FromDominik Hezel <sendme2000@me.com>
Date2012-06-26 08:48 +0000
Message-ID<jsbt0o$6oc$1@smc.vnet.net>
In reply to#10613
On Saturday, June 23, 2012 10:27:43 AM UTC+2, nanobio9 wrote:
> Hi, Helen,
> 
> Thanks for the tip. The code I used was very simple. It was copied
> from the help file of FileNameSetter:
> {FileNameSetter[Dynamic[admittanceFile], "Open", {"mfile" ->
> {"*.m"}}], Dynamic[admittanceFile]}
>

That is nice. Is there a possibility to include FilenNameSetter as a Button in Manipulate? I tried, but failed ...

[toc] | [prev] | [next] | [standalone]


#10598

From"E. Martín-Serrano" <eMartinSerrano@telefonica.net>
Date2012-06-22 09:15 +0000
Message-ID<js1d2u$m8r$1@smc.vnet.net>
In reply to#10571
Hi  KKL

I am not sure whether I understand you question, but I can tell you what I
do to find and  open files of any extension spread over all directories (not
only  those directories managed directly by Mathematica in $Path)

The basic  problem I understand is (a)  I do not use Mathematica as the root
directory for all my notebooks  (b) Although  it can be argued  that is a
good or safe practice to locate all notebooks under the directory
Mathematica,  it is true, too, that not everything in a computer must be
located in that directory, among other reason because some files are shared
by non Mathematica applications. (c) Mathematica provides the tools to do it
easily.

This is an example of what I do (here I use a button but it can be done in
other forms).

ClearAll@fbuttontofile


fbuttontofile::usage = "fbuttontofile[buttonlegend, filename,isize], yields
a button to open any file in any directory from a notebook"


fbuttontofile[buttonlegend_, filename_, isize_: Full] := 
 

Module[{directoryfiles, fullpath, filedirectorypath, button},
  

(* I think this could be down better with Block to avoid saving and
restoring $Path each time the routine is invoked*)
   

bckpath = $Path ;
  

(* locates the directory path to the filename file down  the
$UserDocumentsDirectory *)

Quiet[directoryfiles = FileNames[filename, {"*"}, Infinity]];
  
fullpath = FileNameJoin[{$UserDocumentsDirectory, directoryfiles} //
Flatten];

filedirectorypath =  FileNameTake[fullpath, FileNameDepth[fullpath] - 1];
  
(* adds directory path for the filename file to $Path *)

AppendTo[$Path, filedirectorypath ];

button =  Button[buttonlegend, SystemOpen[filename], ImageSize -> isize];
  
(* I do not know why, but I ought to put this dynamic wrapping here for the
button to work, see that button is local to the module *)


Dynamic@button 

(* I would like to restore $path to its canonical setting here, but it does
work, I mean the button does not work  *)

]

(* restore the canonical value for $Path outside the module *)

$Path = bckpath; 

(* this is done elsewhere outside the function*)

(* the following creates a button to open a file 'external'  to Mathematica
(PDF) *)

fbuttontofile[Style["To Open Existing 'external' PDF File", 12],
"PDFfile.pdf"]

(* the button can be located, inserted or enclosed wherever you want *)

As in, for example

Insert[Framed@Column[{"NonAccelerating Inflation Rate of Unemployment", 
   fbuttontofile[Style["NAIRU (Natural Unemployment)-Ball&Mankiw", 12], 
    "NAIRU-BallMankiw.pdf"]}, Center], {xpos, ypos}]

(* where "NAIRU-BallMankiw.pdf" is a paper on the subject the notebook is
about and is located in a directory which contains docs about inflation and
prices level  nothing about Mathematica *)

So, substitute the file name for any other in your system and it should
work. 

The routine can be improved a lot but it works as it is.

Any clue to improve it would be appreciated

E. Martin-Serrano


On 6/21/2012 5:15 AM, nanobio9 wrote:
> Dear Mathematicans,
>
> Whenever I tried to open a file from my Mathematica directory (with
> rather deep structure), I have to start with "~/Documents/" (I am
> using Mac). I searched the help and I found that this directory is
> coded in the variable "$UserDocumentsDirectory". OK. So I tried to set
> this variable to the root of my Mathematica directory, but I found it
> protected. Then I setup my local "init.m" file. I unprotect it, set
> it, and protect it, in the init.m file. (This is another story though.
> I searched the web for half a day and I do not see any example or
> instruction, official or by other users, on how people can compose
> their own init.m file.) However, nothing is changed.
>
> When my data files grow in number, I decided that I should use the
> "FileNameSetter" interface in my NB to pick the file on the fly. That
> way I do not have to modify the code ( filename=xxxx ...., blablabla )
> for each datafile. However, I found the same problem. In the
> "FileNameSetter" function, there is not an option to set the default
> starting path. (Or I am just too stupid to use electronic
> documentation so that I do not find the solution?) Everything starts
> with "~/Documents", although since the second time the directory tree
> will be expanded like what I saw the previous time (this is the case
> in Mac. I did not try under Windows or Linux).
>
> Is there any smarter way to do this?  Look forward to your helpful
> comments.
>
> KKL
>




[toc] | [prev] | [next] | [standalone]


#10611

FromDavid Bailey <dave@removedbailey.co.uk>
Date2012-06-23 08:22 +0000
Message-ID<js3ucd$ut$1@smc.vnet.net>
In reply to#10571
On 21/06/2012 10:15, nanobio9 wrote:
> Dear Mathematicans,
>
> Whenever I tried to open a file from my Mathematica directory (with
> rather deep structure), I have to start with "~/Documents/" (I am
> using Mac). I searched the help and I found that this directory is
> coded in the variable "$UserDocumentsDirectory". OK. So I tried to set
> this variable to the root of my Mathematica directory, but I found it
> protected. Then I setup my local "init.m" file. I unprotect it, set
> it, and protect it, in the init.m file. (This is another story though.
> I searched the web for half a day and I do not see any example or
> instruction, official or by other users, on how people can compose
> their own init.m file.) However, nothing is changed.
>
> When my data files grow in number, I decided that I should use the
> "FileNameSetter" interface in my NB to pick the file on the fly. That
> way I do not have to modify the code ( filename=xxxx ...., blablabla )
> for each datafile. However, I found the same problem. In the
> "FileNameSetter" function, there is not an option to set the default
> starting path. (Or I am just too stupid to use electronic
> documentation so that I do not find the solution?) Everything starts
> with "~/Documents", although since the second time the directory tree
> will be expanded like what I saw the previous time (this is the case
> in Mac. I did not try under Windows or Linux).
>
> Is there any smarter way to do this?  Look forward to your helpful
> comments.
>
> KKL
>
I use Windows and Linux, and I find it far more convenient to use my own 
directories: c:\whatever, or ~/whatever . This gives one far more 
control, and you can divide files up into sub directories entirely as 
you wish.

David Bailey
http://www.dbaileyconsultancy.co.uk

[toc] | [prev] | [next] | [standalone]


#10623

From"E. Martín-Serrano" <eMartinSerrano@telefonica.net>
Date2012-06-24 08:22 +0000
Message-ID<js6iop$84v$1@smc.vnet.net>
In reply to#10571
Sorry for the following misspelling that led someone to confusion

In my response to this question,

where I said 'Insert' in

Insert[Framed@Column[{"NonAccelerating Inflation Rate of Unemployment",
   fbuttontofile[Style["NAIRU (Natural Unemployment)-Ball&Mankiw", 12],
    "NAIRU-BallMankiw.pdf"]}, Center], {xpos, ypos}]

I should have said 'Inset'

Inset[Framed@Column[{"NonAccelerating Inflation Rate of Unemployment",
   fbuttontofile[Style["NAIRU (Natural Unemployment)-Ball&Mankiw", 12],
    "NAIRU-BallMankiw.pdf"]}, Center], {xpos, ypos}]

Of course 'Insert' doesn't belong to this context and cannot work.

Anyway, that was only for illustration purposes: just about a possible way
of using 'fbuttontofile[]'. But insetting a button (like this) in a graphics
is not probably a good idea, since some objects (like controls) inset in
graphics, at least in my case, tend to create performance problems and even
sometimes doesn't work at all. It is better to put them in columns or rows,
as for example:

Panel[Column[{Framed[
    Plot[{Sin[x] + x/2, Sin[x] + x}, {x, 0, 10},
     Filling -> {1 -> {2}}, ImageSize -> 300,
     Epilog ->
      Inset[Framed[
        Column[{"For detailed info on the function" ,
          "click the button 'NAIRU' below"}, Center],
        FrameStyle -> Lighter[Blue, .3], Background -> LightGray,
        RoundingRadius -> 5], Scaled[{0.32, .7}]]],
    FrameStyle -> Lighter[Brown, .3], Background -> LightYellow],
   Spacer[10],
   fbuttontofile[
    Style["NAIRU (Natural Unemployment)-Ball&Mankiw", 12],
    "NAIRU-BallMankiw.pdf", 280]},  Center],
 Style["NonAccelerating Inflation Rate of Unemployment", Bold]]

Here   'fbuttontofile[]' works nicely.

Sorry again.

E. Martin-Serrano

-----Mensaje original-----
De: E. Mart=EDn-Serrano [mailto:eMartinSerrano@telefonica.net]
Enviado el: viernes, 22 de junio de 2012 11:14
Para: mathgroup@smc.vnet.net
Asunto: Re: Default path for opening files

Hi  KKL

I am not sure whether I understand you question, but I can tell you what I
do to find and  open files of any extension spread over all directories (not
only  those directories managed directly by Mathematica in $Path)

The basic  problem I understand is (a)  I do not use Mathematica as the root
directory for all my notebooks  (b) Although  it can be argued  that is a
good or safe practice to locate all notebooks under the directory
Mathematica,  it is true, too, that not everything in a computer must be
located in that directory, among other reason because some files are shared
by non Mathematica applications. (c) Mathematica provides the tools to do it
easily.

This is an example of what I do (here I use a button but it can be done in
other forms).

ClearAll@fbuttontofile


fbuttontofile::usage = "fbuttontofile[buttonlegend, filename,isize], yields
a button to open any file in any directory from a notebook"


fbuttontofile[buttonlegend_, filename_, isize_: Full] :=

Module[{directoryfiles, fullpath, filedirectorypath, button},
 

(* I think this could be down better with Block to avoid saving and
restoring $Path each time the routine is invoked*)
  

bckpath = $Path ;
 

(* locates the directory path to the filename file down  the
$UserDocumentsDirectory *)

Quiet[directoryfiles = FileNames[filename, {"*"}, Infinity]];
 
fullpath = FileNameJoin[{$UserDocumentsDirectory, directoryfiles} //
Flatten];

filedirectorypath =  FileNameTake[fullpath, FileNameDepth[fullpath] - 1];
 
(* adds directory path for the filename file to $Path *)

AppendTo[$Path, filedirectorypath ];

button =  Button[buttonlegend, SystemOpen[filename], ImageSize -> isize];
 
(* I do not know why, but I ought to put this dynamic wrapping here for the
button to work, see that button is local to the module *)


Dynamic@button

(* I would like to restore $path to its canonical setting here, but it does
work, I mean the button does not work  *)

]

(* restore the canonical value for $Path outside the module *)

$Path = bckpath;

(* this is done elsewhere outside the function*)

(* the following creates a button to open a file 'external'  to Mathematica
(PDF) *)

fbuttontofile[Style["To Open Existing 'external' PDF File", 12],
"PDFfile.pdf"]

(* the button can be located, inserted or enclosed wherever you want *)

As in, for example

Insert[Framed@Column[{"NonAccelerating Inflation Rate of Unemployment",
   fbuttontofile[Style["NAIRU (Natural Unemployment)-Ball&Mankiw", 12],
    "NAIRU-BallMankiw.pdf"]}, Center], {xpos, ypos}]

(* where "NAIRU-BallMankiw.pdf" is a paper on the subject the notebook is
about and is located in a directory which contains docs about inflation and
prices level  nothing about Mathematica *)

So, substitute the file name for any other in your system and it should
work.

The routine can be improved a lot but it works as it is.

Any clue to improve it would be appreciated

E. Martin-Serrano


On 6/21/2012 5:15 AM, nanobio9 wrote:
> Dear Mathematicans,
>
> Whenever I tried to open a file from my Mathematica directory (with
> rather deep structure), I have to start with "~/Documents/" (I am
> using Mac). I searched the help and I found that this directory is
> coded in the variable "$UserDocumentsDirectory". OK. So I tried to set 
> this variable to the root of my Mathematica directory, but I found it
> protected. Then I setup my local "init.m" file. I unprotect it, set
> it, and protect it, in the init.m file. (This is another story though.
> I searched the web for half a day and I do not see any example or
> instruction, official or by other users, on how people can compose
> their own init.m file.) However, nothing is changed.
>
> When my data files grow in number, I decided that I should use the
> "FileNameSetter" interface in my NB to pick the file on the fly. That
> way I do not have to modify the code ( filename=xxxx ...., blablabla )
> for each datafile. However, I found the same problem. In the
> "FileNameSetter" function, there is not an option to set the default
> starting path. (Or I am just too stupid to use electronic
> documentation so that I do not find the solution?) Everything starts
> with "~/Documents", although since the second time the directory tree
> will be expanded like what I saw the previous time (this is the case
> in Mac. I did not try under Windows or Linux).
>
> Is there any smarter way to do this?  Look forward to your helpful
> comments.
>
> KKL
>





[toc] | [prev] | [next] | [standalone]


#10625

Fromawnl <awnl@gmx-topmail.de>
Date2012-06-25 08:02 +0000
Message-ID<js95tt$f3b$1@smc.vnet.net>
In reply to#10571
Hi,

>
> Whenever I tried to open a file from my Mathematica directory (with
> rather deep structure), I have to start with "~/Documents/" (I am
> using Mac). I searched the help and I found that this directory is
> coded in the variable "$UserDocumentsDirectory". OK. So I tried to set
> this variable to the root of my Mathematica directory, but I found it
> protected. Then I setup my local "init.m" file. I unprotect it, set
> it, and protect it, in the init.m file. (This is another story though.
> I searched the web for half a day and I do not see any example or
> instruction, official or by other users, on how people can compose
> their own init.m file.) However, nothing is changed.

There are ways to change some of these "fixed" pathes with environment 
variables or arguments to the executable before you start mathematica. I 
don't know whether $UserDocumentsDirectory is amongst them, but don't 
think so. But I don't think this is what you need. Why don't you just 
use the full file path? You can define:

myRootDirectory = "/path/to/my/data"

and then use something like:

Get[FileNameJoin[{myRootDirectory,"relative/path/to/file.m"}]]


> When my data files grow in number, I decided that I should use the
> "FileNameSetter" interface in my NB to pick the file on the fly. That
> way I do not have to modify the code ( filename=xxxx ...., blablabla )
> for each datafile.

that seems reasonable...

> However, I found the same problem. In the
> "FileNameSetter" function, there is not an option to set the default
> starting path. (Or I am just too stupid to use electronic
> documentation so that I do not find the solution?) Everything starts
> with "~/Documents", although since the second time the directory tree
> will be expanded like what I saw the previous time (this is the case
> in Mac. I did not try under Windows or Linux).
>
> Is there any smarter way to do this?  Look forward to your helpful
> comments.

If you want FileNameSetter to start in a certain directory, give it that 
directory as a first argument. If you want a preselected filename, give 
a full path name and the dialog will open in the directory where that 
file lives (provided the directory does exist). Seems pretty 
straightforward to me, although it admittedly isn't very clear from the 
documentation. So this:

FileNameSetter[FileNameJoin[{$HomeDirectory, "Desktop"}]]

will start the file browseron your desktop, something like this:

filename = "/path/to/my/data/*.m"
FileNameSetter[Dynamic[filename], "Open"]

will open the file browser in /path/to/my/data and use a filter for .m 
files but have no "reasonable" filename selected. There are additionaly 
possibilities to further refine the filter settings, which you can get 
from the documentation.

I know this works for Windows and Linux and have also used this on a 
Mac, but honestly don't exactly remember what the file open dialog will 
actually show, but I would be very surprised if that wouldn't do 
something reasonable on a Mac.

hth,

albert

[toc] | [prev] | [next] | [standalone]


#10639

From"E. Martín-Serrano" <eMartinSerrano@telefonica.net>
Date2012-06-26 08:47 +0000
Message-ID<jsbsvp$6np$1@smc.vnet.net>
In reply to#10571
Hi:

Please, could anyone explain why the 'In[5]:= SetDirectory[directory]'
fails ?

In[1]:= DirectoryStack[]

Out[1]= {}

In[2]:= directory = FileNameJoin[{"C:", "fbuttontofileTest"}]

Out[2]= "C:\\fbuttontofileTest"

In[3]:= directory

Out[3]= "C:\\fbuttontofileTest"

In[4]:= Head@%

Out[4]= String

In[5]:= SetDirectory[directory]

Out[5]= $Failed

In[6]:= DirectoryStack[]

Out[6]= {}

The directory

"C:\fbuttontofileTest"

Does exist in the installation (windows7 MathV8.0.1), although it isn't a
standard Mathematica directory there is not warning on this in the Help
documentation as far as I know.

Best regards.

E. Martin-Serrano



-----Mensaje original-----
De: awnl [mailto:awnl@gmx-topmail.de] 
Enviado el: lunes, 25 de junio de 2012 10:01
Para: mathgroup@smc.vnet.net
Asunto: Re: Default path for opening files

Hi,

>
> Whenever I tried to open a file from my Mathematica directory (with 
> rather deep structure), I have to start with "~/Documents/" (I am 
> using Mac). I searched the help and I found that this directory is 
> coded in the variable "$UserDocumentsDirectory". OK. So I tried to set 
> this variable to the root of my Mathematica directory, but I found it 
> protected. Then I setup my local "init.m" file. I unprotect it, set 
> it, and protect it, in the init.m file. (This is another story though.
> I searched the web for half a day and I do not see any example or 
> instruction, official or by other users, on how people can compose 
> their own init.m file.) However, nothing is changed.

There are ways to change some of these "fixed" pathes with environment
variables or arguments to the executable before you start mathematica. I
don't know whether $UserDocumentsDirectory is amongst them, but don't think
so. But I don't think this is what you need. Why don't you just use the full
file path? You can define:

myRootDirectory = "/path/to/my/data"

and then use something like:

Get[FileNameJoin[{myRootDirectory,"relative/path/to/file.m"}]]


> When my data files grow in number, I decided that I should use the 
> "FileNameSetter" interface in my NB to pick the file on the fly. That 
> way I do not have to modify the code ( filename=xxxx ...., blablabla ) 
> for each datafile.

that seems reasonable...

> However, I found the same problem. In the "FileNameSetter" function, 
> there is not an option to set the default starting path. (Or I am just 
> too stupid to use electronic documentation so that I do not find the 
> solution?) Everything starts with "~/Documents", although since the 
> second time the directory tree will be expanded like what I saw the 
> previous time (this is the case in Mac. I did not try under Windows or 
> Linux).
>
> Is there any smarter way to do this?  Look forward to your helpful 
> comments.

If you want FileNameSetter to start in a certain directory, give it that
directory as a first argument. If you want a preselected filename, give a
full path name and the dialog will open in the directory where that file
lives (provided the directory does exist). Seems pretty straightforward to
me, although it admittedly isn't very clear from the documentation. So this:

FileNameSetter[FileNameJoin[{$HomeDirectory, "Desktop"}]]

will start the file browseron your desktop, something like this:

filename = "/path/to/my/data/*.m"
FileNameSetter[Dynamic[filename], "Open"]

will open the file browser in /path/to/my/data and use a filter for .m files
but have no "reasonable" filename selected. There are additionaly
possibilities to further refine the filter settings, which you can get from
the documentation.

I know this works for Windows and Linux and have also used this on a Mac,
but honestly don't exactly remember what the file open dialog will actually
show, but I would be very surprised if that wouldn't do something reasonable
on a Mac.

hth,

albert


[toc] | [prev] | [next] | [standalone]


#10720

Fromnanobio9 <kuokan.liang@gmail.com>
Date2012-07-01 06:13 +0000
Message-ID<jsopq9$11o$1@smc.vnet.net>
In reply to#10571
Hi, all,

Thanks to all of the replies.
I prefer simpler and more portable solutions. Who does not? So I will merge the most elegant parts of your replies in my program.

The thing is that I have Mathematica available on 6 different computers. Some of them are managed by myself, and some are public servers. I have a Subversion repository for maintaining and distributing the codes. To think that my codes will even be used by some colleagues, I cannot be totally sure that all copies of the codes will be executed under the same environment. That still bothers me. I will try to figure out whether a really smarter solution can be found, based on all replies here.

Best regards to all of you!

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web