Effacer les filtres
Effacer les filtres

Saving current progam folder path

4 vues (au cours des 30 derniers jours)
Jason
Jason le 27 Mar 2014
Commenté : Jason le 27 Mar 2014
Hi. I want to save the location of the current m file folder.
%Save current app directory to a txt file
prog = mfilename('fullpath'); %Get current program path & name
[progpath,name,ext] = fileparts(prog); %Split out folderpath
pathtext = fullfile(progpath,'lastdir.txt') %Build new filename
save('pathtext','progpath','-ascii');
But using the above results in the text file (lastdir.txt) containing only numbers?
  1 commentaire
Jason
Jason le 27 Mar 2014
Perfect, thankyou

Connectez-vous pour commenter.

Réponse acceptée

Jacob Halbrooks
Jacob Halbrooks le 27 Mar 2014
Modifié(e) : Jacob Halbrooks le 27 Mar 2014
It looks like you want to write a string to the text file, but SAVE is not a good fit for this. The help for SAVE -ASCII explains:
* MATLAB translates characters to their corresponding internal
ASCII codes. For example, 'abc' appears in an ASCII file as:
9.7000000e+001 9.8000000e+001 9.9000000e+001
I would suggest you use a different function for writing the file, such as FPRINTF:
prog = mfilename('fullpath'); %Get current program path & name
[progpath,name,ext] = fileparts(prog); %Split out folderpath
pathtext = fullfile(progpath,'lastdir.txt') %Build new filename
fid = fopen(pathtext, 'w');
fprintf(fid, '%s', progpath);
fclose(fid);

Plus de réponses (0)

Catégories

En savoir plus sur Environment and Settings 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