Replacing "dir" when deploying a GUI

4 ビュー (過去 30 日間)
Edison
Edison 2018 年 7 月 26 日
コメント済み: OCDER 2018 年 7 月 26 日
When turning a GUI into a standalone application i found out that the function "dir" i was using to get the names of the files in a folder, is not working. Using MATLAB Compiler i could add these files to the executable but i don't know how to get their names now i can't use this function, is there a similar one that works in a deployed code?
  3 件のコメント
OCDER
OCDER 2018 年 7 月 26 日
Can you show us an example code of how dir is used?
Edison
Edison 2018 年 7 月 26 日
a=dir('*.xlsx'); b=extractfield(a,'name');
Indeed the function works, but it refers to the files in the executable folder, instead of that i need a function that refers to files in the ctffile

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

採用された回答

OCDER
OCDER 2018 年 7 月 26 日
Try this:
if isdeployed
a = dir(fullfile(ctfroot, '**', '*.xlsx')); %remove '**' if you know a precise folder location.
assert(~isempty(a), 'ERROR: Could not find a file at "%s".', fullfile(ctfroot, '**', '*.xlsx'))
else
a = dir(fullfile(my_root, '**', '*.xlsx')); %my_root is some other "main" dir of your codes
assert(~isempty(a), 'ERROR: Could not find a file at "%s".', fullfile(my_root, '**', '*.xlsx'))
end
  2 件のコメント
Edison
Edison 2018 年 7 月 26 日
Thanks. It now recognizes the files. How can i open one of them using "winopen". Do i have to use "ctfroot" again?
OCDER
OCDER 2018 年 7 月 26 日
Since you already found the directory using dir, you could try this:
XlsFile = fullfile(a(1).folder, a(1).name)
winopen(XlsFile)
Or this could work if you know the exact excel file name because deployed applications has its own paths - so it should find the file for you.
winopen('XlsFileName.xlsx')

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by