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


Groups > comp.soft-sys.math.mathematica > #10639

Re: Default path for opening files

From "E. Martín-Serrano" <eMartinSerrano@telefonica.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Default path for opening files
Date 2012-06-26 08:47 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jsbsvp$6np$1@smc.vnet.net> (permalink)
References <jruonq$fgs$1@smc.vnet.net> <201206250801.EAA15446@smc.vnet.net>

Show all headers | View raw


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


Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web