MathGroup Archive 2005

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

Search the Archive

Re: Portable Notebooks and Filenames[]

  • To: mathgroup at
  • Subject: [mg58047] Re: Portable Notebooks and Filenames[]
  • From: "John Jowett" <John.Jowett at>
  • Date: Fri, 17 Jun 2005 05:18:45 -0400 (EDT)
  • Organization: CERN - European Laboratory for Particle Physics
  • References: <d8e4e7$gik$>
  • Sender: owner-wri-mathgroup at

         I've worked in a very similar situation for many years, using a 
file system accessible from both Windows and Linux.  With a little care, all 
my Mathematica notebooks work unchanged on either system.

The following are fictititious names, just to illustrate.

Suppose that the root of the file system appears as "/universalfs" in Linux 
and is mounted as drive U: in Windows.   Then something like the following 
is a convenient setup (sorry I don't know the right syntax for Mac):

uRoot = Switch[$OperatingSystem, "Windows", "U:", "Unix", "/universalfs", 
"MacOSX", "HD"]

so you can do things like

SetDirectory[ToFileName[{uRoot, "users", "fred", "work"} ]]

Get[ToFileName[{uRoot, "users", "fred", "setup"}, "myfunctions.m" ]]

I actually have more elaborate things in a package that I always load but 
this gives the basic idea.   You can still use it even if you don't have 
access to a common system but just work with parallel structures.

Of course if you just want to work relative to an initial starting folder 
with sub-folders then you don't even need uRoot.

John Jowett

"frank" <frank at> wrote in message 
news:d8e4e7$gik$1 at

> Hi,
> in our group we are using Mathematica both on Windows and on Linux (and
> I'm about to convert a MacAddict to Mathematica).  However, we are
> facing one problem with external file names.
> It is possible to use
> In[1]:=
> SetDirectory["some/directory/subdirectory"];
> (from a syntax point of view; of course the beginning of the string will
> be different, like ~/netdrive vs. w:)
> On the other hand, this works only on Linux:
> In[2]:=FileNames["subdir/*"]
> while on Windows, only this construct works:
> In[3]:=FileNames["subdir\\*"]
> (\ needs to be escaped because \* or nearly any \<letter> combination
> has some meaning).
> This is weird - first because Windows understands the forward slash as a
> directory separator, and second because it means we have to do
> search-replace orgies when trying a notebook on a different OS.  This
> would not only happen in a preamble part, but we even have some
> functions that read all data in a subdirectory, for a list of
> subdirectories.
> Is there a way to write such expressions portable?  Is there, for
> example, an internal variable "directory separator" that could be used
> in this string?  Alternatively, if it's possible to replace \\ by / (and
> vice versa) by some string matching mechanism, we could write a function
> that does this if some boolean is set once in the notebook, or even
> depending on some internal variable that indicates the OS?
> Regards, Frank
> -- 
> Frank Küster
> Inst. f. Biochemie der Univ. Zürich
> Debian Developer

  • Prev by Date: Re: New Mathematica visualization website
  • Next by Date: Re: can anyone solve this equation?
  • Previous by thread: Re: Portable Notebooks and Filenames[]
  • Next by thread: Re: Re: Portable Notebooks and Filenames[]