Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having a problem setting the working directory. I want to do some computation and save my data at one location (D), but in the code below you can see that mathematica shifts automatically to a different location (C). How to use D partition for calculating if mathematica is installed on C?

When I run the code shown below, the file is saved on D but first it is saved on C and on C I don't have enough space.

  In[7]:= ResetDirectory[] 


  In[8]:= DirectoryStack[]

  Out[8]= {}

  In[10]:= SetDirectory["D:\\"]

  Out[10]= "D:\\"


  Export["A.wdx", A];

  In[13]:= DirectoryStack[] 

share|improve this question
What is the value of $TemporaryDirectory? – celtschk May 2 '12 at 21:34
Can you change SetDirectory["D:\\"] to SetDirectory[$TemporaryDirectory] and rerun the whole program? – qazwsx May 2 '12 at 21:43
As reality check, have a look if and where "A.wdx" is in fact saved...? – Yves Klett May 3 '12 at 9:43

The Documentation page for ResetDirectory says under "MORE INFORMATION" field:

Successive calls to ResetDirectory yield earlier and earlier current directories.

ResetDirectory uses the directory stack given by DirectoryStack[].

ResetDirectory removes the last element from the directory stack, and makes the second-to-last element current.

And the page for DirectoryStack[] says:

Each call to SetDirectory prepends one element to the directory stack; each call to ResetDirectory drops one.

So it is not surprizing that DirectoryStack[] initially is a blank list. The call to SetDirectory adds to this list one element: previous working directory. To get the current working directory you should evaluate Directory[].

share|improve this answer

The exact code (I also happen to have a D partition:) runs fine on my computer (Win7, mma 8). The file is created in D:\, just the output of DirectoryStack is misleading. I don't really know, why it doesn't include D:\

You can check your current working directory using Directoy.


(* ==> "E:\\Projekti\\MD\\SCRIPTS\\mathematica\\FitSpectra" *)


(* ==> {"C:\\Users\\ajasja\\Documents"} *)


(* ==> "D:\\" *)

A := 5;

Export["A.wdx", A];


==> {"E:\\Projekti\\MD\\SCRIPTS\\mathematica\\FitSpectra", \


(* ==> "D:\\" *)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.