For stand-alone exe, how do I include a folder of files and know how to access them.

14 vues (au cours des 30 derniers jours)
I have a folder of files I have added to a stand-alone exe. I have been using Desktop->WindowsStandAloneApplication -> Build. There is a link to add files or directories. I have added a folder which has my data files. However, I don't know how to access them. I have tried
if isdeployed
mydir = ctfroot ;
myfile = 'myfile.dat';
fid=fopen([mydir, myfile]);
else
...
end
but it doesn't find the file.

Réponse acceptée

Friedrich
Friedrich le 18 Jan 2013
Modifié(e) : Friedrich le 18 Jan 2013
Hi,
everything you add to your project will keep the same folder hierachy. So lets say you have a folder called myfolder and in there a file called myfile.dat. Then you would need to do:
if isdeployed
fid = fopen(fullfile(ctfroot,'myfolder','myfile.dat'))
end
You can also compile once and not embed the CTF. After compilation, open the ctf file in some zip programm and take a look at the folder structure.

Plus de réponses (2)

owr
owr le 18 Jan 2013
When you concatenate strings using "[...]" the way you wrote above you are missing the "\" between the file name and path (on Windows at least):
mydir = ctfroot ;
myfile = 'myfile.dat';
[mydir, myfile]
ans =
C:\Program Files\MATLAB\R2012amyfile.dat
This would work better:
mydir = ctfroot ;
myfile = 'myfile.dat';
[mydir,'\',myfile]
ans =
C:\Program Files\MATLAB\R2012a\myfile.dat
But Friedrich's suggestion above to use "fullfile" is a cleaner more robust solution to accomplish the same thing.

sara selim
sara selim le 24 Mai 2015
Hi , i have the same problem i tried alot of solution but all of them were wrong , can you tell me how you have solved your problem ?

Catégories

En savoir plus sur Application Deployment dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by