MATLAB Answers

File path containing %

35 views (last 30 days)
I would like to get the path for directories containing % (like %MATLAB_ROOT%, %APPDATA%, etc.) in Windows. However, functions like fileparts cannot interpret the percent sign. Is there a way to make this possible within MATLAB, or the only solution is to call system commands?
Thanks, Zoli

  0 Comments

Sign in to comment.

Accepted Answer

per isakson
per isakson on 13 Aug 2015
Edited: per isakson on 13 Aug 2015
Use getenv, Environment variable to get values of environment variables of the underlying operating system, e.g.
>> getenv('OS')
ans =
Windows_NT
>> getenv('APPDATA')
ans =
C:\Users\poi\AppData\Roaming
%NAME% gets the value of NAME in the Command Prompt, e.g.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\poi>echo %APPDATA%
C:\Users\poi\AppData\Roaming
C:\Users\poi>
And there is the Matlab function, matlabroot
>> matlabroot
ans =
C:\Program Files\MATLAB\R2013b

  1 Comment

Zoltán Csáti
Zoltán Csáti on 14 Aug 2015
I looked into getenv before, but somehow I missed it. Thank you!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by