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 !
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".
- 235,386
- 17
- 334
- 747
-
What version of Mma are you running? According to the docs, prior to 7.0 the value of
$TemporaryPrefixwas used forOpenWrite[]andCreateDirectory[]. – dionys Oct 21 '14 at 08:46 -
@dionys V10.0.1, Mac OSX 10.9.5. Good call - it is in fact
$TemporaryPrefixthat'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
- 51
- 3
-
3
-
2You should consider accepting @MichaelE2´s answer - he proposed the same solution 12hrs earlier... – Yves Klett Oct 21 '14 at 04: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 04:20
-
$TemporaryDirectorygives the main system directory for temporary files on your computer system. Its reporting a system variable, not defining where it should be. – rhermans Oct 20 '14 at 09:49