Is it possible to change dynamically the PATH?

조회 수: 5 (최근 30일)
Tony Castillo
Tony Castillo 2022년 2월 4일
댓글: Tony Castillo 2022년 2월 4일
Dear Mathcoders,
I have this issue, form time to time I switch from two different PCs and even I have backed everything on GitHub, I have to re-write the path because each PC has a different path for the same folder, I mean in my workstation it as follow:
Warning: Name is nonexistent or not a directory:
C:\Users\tonycast\Documents\GitHub\NewValues_SC_ED_2910\.\NV_SCS_ED_2
> In path (line 109)
In addpath (line 86)
In PVGeo_SCandSociety_StateFlow (line 426)
Meanwhile in my laptop, it is:
C:\Users\TCC\Documents\GitHub\NewValues_SC_ED_2910\.\NV_SCS_ED_2
I just want to know is there any way to make this change on the path dynamically?
How can I workaround this?
Thanks

채택된 답변

Max Heimann
Max Heimann 2022년 2월 4일
편집: Max Heimann 2022년 2월 4일
You can use the "mfilename" command to get the path of the currently running script and define a relative path from there.
[fname,fpath] = fileparts(mfilename('fullpath'));
Now you can go up in the folder structure from the path of the script with '..' in the path. (This obviosuly depends on your folder structure and requires the structure to be identical in both environments). E.g.:
path2item = [fpath filesep '..' filesep '..' filesep 'NewValues_SC_ED_2910']
Alternatively you can simply check for the username in the path and build an if/else statement depending on the username. Or you get the username with
char(java.lang.System.getProperty('user.name'))
  댓글 수: 1
Tony Castillo
Tony Castillo 2022년 2월 4일
Thank you so much, I have used the last alternative
char(java.lang.System.getProperty('user.name'))
And it it worked.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by