Saving current progam folder path

1 回表示 (過去 30 日間)
Jason
Jason 2014 年 3 月 27 日
コメント済み: Jason 2014 年 3 月 27 日
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 件のコメント
Jason
Jason 2014 年 3 月 27 日
Perfect, thankyou

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

採用された回答

Jacob Halbrooks
Jacob Halbrooks 2014 年 3 月 27 日
編集済み: Jacob Halbrooks 2014 年 3 月 27 日
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);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by