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[] 

  • 1
    $\begingroup$ What is the value of $TemporaryDirectory? $\endgroup$
    – celtschk
    May 2, 2012 at 21:34
  • $\begingroup$ Can you change SetDirectory["D:\\"] to SetDirectory[$TemporaryDirectory] and rerun the whole program? $\endgroup$
    – user13253
    May 2, 2012 at 21:43
  • 1
    $\begingroup$ As reality check, have a look if and where "A.wdx" is in fact saved...? $\endgroup$
    – Yves Klett
    May 3, 2012 at 9:43

2 Answers 2


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[].


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:\\" *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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