Error with tempname and tempdir

Recently I noticed that tempname and tempdir are not working anymore on my computer. Any ideas about why I get the following error messages? I checked and I have the ...Local\Temp folder where it is supposed to be...
>> tmp_nam = tempname
Error using cd
Cannot CD to C:\Users\Razvan\AppData\Local\Temp (Name is nonexistent or not a directory).
Error in tempdir (line 31)
curr_dir = cd(tmp_dir);
Error in tempname (line 18)
dirname = tempdir;
>> tmp_folder = tempdir
Error using cd
Cannot CD to C:\Users\Razvan\AppData\Local\Temp (Name is nonexistent or not a directory).
Error in tempdir (line 31)
curr_dir = cd(tmp_dir);
If I run Matlab "as Administrator" then the 2 commands work...
Thanks, Razvan

2 个评论

Those commands work fine for me and I'm not running as administrator.
Right_Click_Matlab_Shortcut < Properties < Shortcut < Advanced < Select Run as Administrator < OK < OK

请先登录,再进行评论。

回答(4 个)

Walter Roberson
Walter Roberson 2013-1-17

1 个投票

Possibly one of the directories along the way does not allow you read permission (or, if it was Unix, execute permission would be needed.) Use Windows Explorer to check the Security Settings on the path; also verify that the directory is owned by you.

2 个评论

Razvan
Razvan 2013-1-17
编辑:Razvan 2013-1-17
I use Windows 7. How can I check the security settings and what should I set there to have all the permissions necessary for Matlab to work? I noticed that if I run Matlab "as Administrator" then the 2 commands work...

请先登录,再进行评论。

Those commands work fine for me and I'm not running as administrator.
>> tmp_nam = tempname
tmp_nam =
C:\Users\Razvan\AppData\Local\Temp\tpdcd91567_4e74_43ae_aaf4_64dec3b0aa6d
>> tmp_folder = tempdir
tmp_folder =
C:\Users\Razvan\AppData\Local\Temp\
Both the file and folder you're allowed to write to even if you don't have admin authority. What I don't understand is why it's trying to cd to the folder. The help says "tmp_folder = tempdir returns the name of the system's temporary folder, if one exists. This function does not create a new folder. " so it's not supposed to create it or change to it. Are you sure you didn't redefine them? What does "which -all tempdir" say?

8 个评论

Thanks! No, I didn't redefine any Matlab functions. Here is the output of the command you asked for:
>> which -all tempdir
C:\Program Files\MATLAB\R2012b\toolbox\matlab\iofun\tempdir.m
Please let me know if you have any other ideas to debug this. Thanks!
Try this exactly as below, and copy and paste results back here:
echo on
try
tempdir
catch ME
errorMessage = sprintf('Error calling tempdir.\n\nError Message:\n%s', ME.message);
fprintf(1,'%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
try
tempname
catch ME
errorMessage = sprintf('Error calling tempname.\n\nError Message:\n%s', ME.message);
fprintf(1,'%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
try
cd C:\Users\Razvan\AppData\Local\Temp
catch ME
errorMessage = sprintf('Error calling cd.\n\nError Message:\n%s', ME.message);
fprintf(1,'%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
The error message in the command window is:
Error calling tempdir.
Error Message:
Cannot CD to C:\Users\Razvan\AppData\Local\Temp (Name is nonexistent or not a directory).
Error calling tempname.
Error Message:
Cannot CD to C:\Users\Razvan\AppData\Local\Temp (Name is nonexistent or not a directory).
Error calling cd.
Error Message:
Cannot CD to C:\Users\Razvan\AppData\Local\Temp (Name is nonexistent or not a directory).
I also get 3 warning windows:
Error calling tempdir/tempname/CD
Error Message: Cannot CD to C:\Users\Razvan\AppData\Local\Temp (Name is nonexistent or not a directory).
Please let me know if I can try something else.
You said that you have this folder: "C:\Users\Razvan\AppData\Local\Temp" but it's telling you that you don't. Are you 100% sure that you have that folder? Browse to it with Windows Explorer.
Yes, I have the folder there. For some strange reason in "cmd" also I get "Access denied" when I try to cd there, if I don't run this "as Administrator"... So I guess it is a problem with the permissions in my windows... Do you know how to fix these? I never changed those myself...
If you say cmd, what directory does it put you at when it opens the console window?
C:\Users\Razvan>
You do not have permission to write to that folder, I don't think. It has to be in the Documents subfolder of that.

请先登录,再进行评论。

Razvan
Razvan 2013-1-20

0 个投票

I found the problem on another forum... The SYSTEM has to have full permissions in the TEMP folder... and somehow this was removed by some program... I added back the full permissions to SYSTEM and now it seems to work...
Thanks for your help!

1 个评论

Thank you very much, I had the same problem and could not even run simulink, unless I run Matlab as administrator (which was a problem as files I opened from windows explorer were opening on a new instance of matlab).
Thanks everyone who helped us!

请先登录,再进行评论。

Sebastian Pakula
Sebastian Pakula 2020-7-27
I had a similar problem, but the problem was Dropbox folder which prevent getting access to it. The solution is to stop synchronizing Dropbox during the running program.

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by