problem with "cd" and network drive

14 ビュー (過去 30 日間)
Christian
Christian 2019 年 7 月 19 日
編集済み: Christian 2019 年 7 月 19 日
Hello everybody,
I'd like to implement a line of code into my app that changes the current directory to the directory of the app. I have tried for so many hours now but haven't succeeded and I hope that you can help me now.
[filepath,~,~] = fileparts(mfilename('fullpath'))
-> filepath = '\\university-pc04\shared\scripts\apps'
cd filepath
-> Error using cd
Cannot CD to \\univesity-pc04\shared\filepath (Name is nonexistent or not a directory).
It's strange that it does not say "Cannot CD to \\university-pc04\shared\scripts\apps (Name is nonexistent or not a directory)."! Why is there "filepath" in the error message instead?
But it works by copying and pasting the path:
cd '\\university-pc04\shared\scripts\apps''
Where is the problem? Does cd not work with network drives?
Cheers, Christian

採用された回答

Guillaume
Guillaume 2019 年 7 月 19 日
cd filepath
is the command form of cd. The fact that filepath is purple is a hint that filepath is being treated as literal text and not a variable name. The equivalent functional form is:
cd('filepath');
whereas you meant
cd(filepath); %notice that filepath is no longer purple!
  1 件のコメント
Christian
Christian 2019 年 7 月 19 日
編集済み: Christian 2019 年 7 月 19 日
Oh man....
Didn't see the wood for the trees!
Thank you :)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSearch Path についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by