Why does Copyfile not work in Matlab Deployed GUI?

4 ビュー (過去 30 日間)
Ravi Goyal
Ravi Goyal 2015 年 12 月 4 日
コメント済み: Ravi Goyal 2015 年 12 月 4 日
I build a GUI which I deploy, using the Application compiler. I want to create a folder and copy the folder to a location. This is my code:
try
%MODEL FOLDER EXISTS --> COPY ELEMENTS
if exist('C:\All_Fit\models','dir')==7
[~,message]=copyfile('models/*','C:/All_Fit/models','f'); %SLASH INSTEAD OF BACKSLASH
warndlg(message)
model_folder='C:\All_Fit\models';
%MODEL DOES NOT EXIST --> CREATE FOLDER THEN COPY ELEMENTS
elseif exist('C:\All_Fit\models','dir')==0
mkdir('C:\All_Fit','models')
[~,message]=copyfile('models/*','C:/All_Fit/models','f'); %SLASH INSTEAD OF BACKSLASH
warndlg(message)
model_folder='C:\All_Fit\models';
%MODEL FOLDER FROM INTERNAL FOLDER
else
warndlg(sprintf('No model molder could be found or created. The internally definded models are used.'))
model_folder='models';
end
catch
warndlg(sprintf('No Model Folder could be found or created. The internally definded models are used.'))
model_folder='models';
end
I have tried different syntax for copyfile and all of the succeded under pure Matlab. For instance:
copyfile('models','C:\All_Fit\models','f');
The message I get from the warndlg is 'No matching files were found'. Yet the catch gets the folder and uses them.
Why is that not working in the exe. since it works like a charm if not deployed? Thanks a lot. Ravi

採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 4 日
You are copying from a relative path, not from an absolute path. That can only succeed if you are cd'd to the correct location. You would be safer copying an absolute path.
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 12 月 4 日
編集済み: Walter Roberson 2015 年 12 月 4 日
... and why isn't your code checking that the source directory exists?
Ravi Goyal
Ravi Goyal 2015 年 12 月 4 日
Dear Walter, thanks a lot. Due to your hint and some more searching I could solve the problem. I did not know that the relative path is based basically from within the ctfroot structure. Thanks! For everybody else changed the copyfile line to
copyfile(fullfile(ctfroot, 'models'),'C:/All_Fit/models','f');
More Information can be found here (if you know what to look for ;)
Thanks Ravi

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by