# Change Temporary Directory

How to change the value of $TemporaryDirectory ? I need to change it because there is not enough space on the C drive and the calculation seems to stop after a while ! • TempDir is the default directory for windows and not only for mathematica. It seems mathematica doesn't create anything automatically in this directory except using createdirectory and so on without specific path. Are you sure that mathematica writes right in this directory? The simplest thing you can try to redirect input is to use setdirectory to the folder that you want. – funnyp0ny Oct 20 '14 at 9:23 • What kind of operation do you have problems with? – Yves Klett Oct 20 '14 at 9:23 • Hi, welcome to Mathematica.SE, please consider taking the tour so you learn the basics of the site. Once you gain enough reputation by making good questions you will be able to vote up and down both questions and answers. When you see good ones, please vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. As you receive help, try to give it too, by answering questions in your area of expertise. – rhermans Oct 20 '14 at 9:33 • If you are in Windows, on System Properties, Environment Variables, you could change the TMP and TEMP variables to point to other folders. But do this carefully and only after understanding what you are doing. Anyhow, this seems to be off-topic and its likely to be closed. – rhermans Oct 20 '14 at 9:36 • I do not really get the downvote. The question does raise an interesting point (even if most users never come across the issue). – Yves Klett Oct 20 '14 at 14:47 ## 2 Answers Just set$TemporaryDirectory to a desired directory. You can use system commands such as FileNameJoin or FileNameSetter to create a directory name appropriate to your system. I have a unix-based Mac, so I ran an example using

$TemporaryDirectory = "/tmp/math" Here is the example from the docs for OpenWrite, executed under this new setting. Create and open a new stream for writing: fname = FileNameJoin[{$TemporaryDirectory, "testfile"}];

s = OpenWrite[fname]

(* OutputStream["/tmp/math/testfile", 145] *)

Write an expression to the stream:

Write[s, Expand[(x + y)^10]]

Close the stream:

Close[s]

(* "/tmp/math/testfile" *)

And so on.

Caveat: On my system, the temporary directory used for

s = OpenWrite[]

(from the docs for $TemporaryDirectory) is not$TemporaryDirectory, but some file in a random-looking sub-sub-directory: "/var/folders/9d/68khy4s15sjf9qfpnhqz9tnc0000gn/T/m000003840331".

• What version of Mma are you running? According to the docs, prior to 7.0 the value of $TemporaryPrefix was used for OpenWrite[] and CreateDirectory[]. – dionys Oct 21 '14 at 8:46 • @dionys V10.0.1, Mac OSX 10.9.5. Good call - it is in fact$TemporaryPrefix that's being used. Am I the only one? – Michael E2 Oct 21 '14 at 11:32
• It is the same on my system, V10.0.1, Windows x64 .. defaults determined by $TemporaryPrefix (despite what's stated in the docs). – dionys Oct 21 '14 at 12:15 I got the answer from Mathematica Forum on Wolfram website. "If you wish to change the value of$TemporaryDirectory for a particular Mathematica session then you can simply execute

$TemporaryDirectory="path to a new directory" since$TemporaryDirectory is not Protected"

Thanks to David Reiss

• Um, that's what I said... – Michael E2 Oct 21 '14 at 3:41
• You should consider accepting @MichaelE2´s answer - he proposed the same solution 12hrs earlier... – Yves Klett Oct 21 '14 at 4:54
• Thanks a lot Michael. Yes, you're right. Sorry, I'm new here. I didn't know that there is "accept answer" button. – Mohamed Ibrahim Oct 22 '14 at 4:20
• I don't have enough reputation to Vote up your answer :( – Mohamed Ibrahim Oct 22 '14 at 4:22